Asherlc Asherlc - 1 year ago 122
Javascript Question

Chain ES7 async functions

In an ES7 async function, I can get an asynchronous value like so:

const foo = await myAsyncFunction()

If I want to call a method on the result, with a sync function I'd do something like

Is it possible to chain calls with async functions, or do you have to assign a new variable for each result?

Answer Source

You can await in an expression, no need to assign it to a new variable.

const foo = await (await myAsyncFunction()).somethingElse()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download