Lesson 14
Async / Await
Lesson 14 — Async / Await
日本語Syntax
Declare async functions with async fn. They return a Promise. Use await inside them to wait for other Promises:
async fn fetch-data url
const res be await fetch[url]
return await res.json[]
Anonymous async functions work too:
const handler be async fn event to await process[event]
Task
Make compute:
1. await slow-double[x] and store the result
2. return the result plus 1
So compute[5] resolves to 11.
Check
npm test 14
Learn more
Loading editor...
Press Ctrl+Enter to run