20 lines
464 B
Markdown
20 lines
464 B
Markdown
|
|
# Call async from non-async
|
|
|
|
We have a "regular" function. How to call `async` from it and use its result?
|
|
|
|
```js
|
|
async function wait() {
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
return 10;
|
|
}
|
|
|
|
function f() {
|
|
// ...what to write here?
|
|
// we need to call async wait() and wait to get 10
|
|
// remember, we can't use "await"
|
|
}
|
|
```
|
|
|
|
P.S. The task is technically very simple, but the question is quite common for developers new to async/await.
|