Examples of Async-Await
Fri Sep 11 2020 07:50:15 GMT+0000 (UTC)
Posted by
@darshjain
#dart
//I think your understanding of Promises and async/await is not correct.
//When you make a function async, the await keyword before a promise make sure
//that code execution will pause until the promise fulfilled or rejected.
//Your code can be simplified:
var currentPromise;
async function asyncFunc(promise){
// Do some code here
return await promise;
}
function anotherFunction(){
asyncFunc(currentPromise);
}
//When we are calling return await promise, the execution engine waits in a
//non-blocking way until the promise fulfilled or rejected, and then it returns
//the output to the anotherFunction function.
content_copy Copy
Examples for StackOverflow
Comments