id | keywords | name | summary | category | |
---|---|---|---|---|---|
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.
<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+"");}