Skip to content

Add documentation for async/await. #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 6, 2022
Prev Previous commit
Next Next commit
Review comments.
  • Loading branch information
cristianoc committed Nov 5, 2022
commit ff745d26488a130ae9ab5420357cbcf562163cc4
8 changes: 4 additions & 4 deletions pages/docs/manual/latest/function.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ If you write down the uncurried function's type, you'll add a dot there as well.

**This feature seems trivial**, but is actually one of our most important features, as a primarily functional language. We encourage you to use it if you'd like to remove any mention of `Curry` runtime in the JS output.

## Async/Await (from version v10.1)
## Async/Await (from v10.1)

Just as in JS, an async function can be declared by adding `async` before the definition, and `await` can be used in the body of such functions.
The outpul looks like idiomatic JS:
The output looks like idiomatic JS:

<CodeTab labels={["ReScript", "JS Output"]}>

Expand All @@ -438,7 +438,7 @@ async function greetUser(userId) {
```
</CodeTab>

The return type of `getUser` is inferred to be `promise<string>`, where type `promise` is now a built-in of the language.
The return type of `getUser` is inferred to be `promise<string>`.
Similarly, `await getUserName(userId)` returns a `string` when the function returns `promise<string>`.
Using `await` outside of an `async` function (including in a non-async callback to an async function) is an error.

Expand All @@ -463,7 +463,7 @@ let someAsyncFn = async () => {
}
```
```js
var SomeReScriptException = /* @__PURE__ */Caml_exceptions.create("JsxV4.SomeReScriptException");
var SomeReScriptException = /* @__PURE__ */Caml_exceptions.create("Example.SomeReScriptException");

async function someAsyncFn(param) {
var data;
Expand Down