Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 1.31 KB

language_async.mdx

File metadata and controls

45 lines (33 loc) · 1.31 KB
idkeywordsnamesummarycategory
async
async
async
This is the `async` keyword.
languageconstructs

Since 10.1

Use the async keyword to make a function asynchronous. An async function may use the await keyword to unwrap a promise value in a seamingly synchronous manner.

Example

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

// Some fictive functionality that offers asynchronous network actions @valexternalfetchUserMail: string=>promise<string> ="GlobalAPI.fetchUserMail" @valexternalsendAnalytics: string=>promise<unit> ="GlobalAPI.sendAnalytics"// We use the `async` keyword to allow the use of `await` in the function bodyletlogUserDetails=async (userId: string) => { // We use `await` to fetch the user email from our fictive user endpointletemail=awaitfetchUserMail(userId) awaitsendAnalytics(`User details have been logged for ${userId}`) Console.log(`Email address for user ${userId}: ${email}`) }
asyncfunctionlogUserDetails(userId){varemail=awaitGlobalAPI.fetchUserMail(userId);awaitGlobalAPI.sendAnalytics("User details have been logged for "+userId+"");console.log("Email address for user "+userId+": "+email+"");}

References

close