Asynchronous Function Chains

In an async function, I can get the asynchronous value as follows:

const foo = await myAsyncFunction()

If I want to call a method for the result, using the synchronization function, I would do something like myAsyncFunction().somethingElse()

Is it possible to associate calls with asynchronous functions, or do you need to assign a new variable for each result?

+5
source share
1 answer

You can wait in the expression, you do not need to assign it to a new variable.

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

Or if you want to call the synchronization method for the result:

 const foo = (await myAsyncFunction()).somethingElseSync() 
+14
source

All Articles