Async functions also return promises that resolve with the return value.
const wait = () => new Promise(resolve => { setTimeout(resolve, 3000); }); const waitAndReturn = async () => { await wait(); // throw new Error('oops!'); throwing rejects return 'hi'; };
So the last example can even be written like:
const createSomePromise = async () => { // make HTTP request return result; };
Small correction here ...
const createSomePromise = async () => { // await HTTP request's response return result; };
Thanks for making that clearer Kumar!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Async functions also return promises that resolve with the return value.
So the last example can even be written like:
Small correction here ...
Thanks for making that clearer Kumar!