Monday, 13 July 2020

Does an async function necessarily returns a promise ?

Hi,So I wrote an async function that runs lots of HTTP requests in a loop. At the end of each iteration of the loop I wanted to then post some data to my server. I want it to be synchronous so I did it using await new Promise(() => axios.post(...)). However, once the first batch of data was sent to the server after the first iteration of the loop, Javascript returned from the loop and the program finished running.I managed to solve this by running the post request using Promise.all. Is this because Javascript implicitly returns when it sees a new Promise ?Thanks.

Submitted July 13, 2020 at 01:06PM by to_fl

No comments:

Post a Comment