Asherlc Asherlc - 5 months ago 37
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?


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

const foo = await (await myAsyncFunction()).somethingElse()