user2229824
user2229824

Reputation: 21

Will an async function inside another function continue running after the function has returned?

Sorry if its a really naive question. I have described the situation as follows. My question is, will OtherAsyncFunction() continue and complete its execution if runThis() returns prematurely?

var a = await runThis(); 

async function runThis(){
   // ... 
   OtherAsyncFunction(); 
   // ... 
   return await someOtherAsyncFunction;  
}

Upvotes: 1

Views: 60

Answers (1)

Kevin Li
Kevin Li

Reputation: 2114

It will still execute OtherAsyncFunction, unless you do await OtherAsyncFunction().

An async function can contain an await expression that pauses the execution of the async function and waits for the passed Promise's resolution, and then resumes the async function's execution and returns the resolved value. See more details here

Upvotes: 3

Related Questions