Skip to content Skip to sidebar Skip to footer

Progress Of Promises

Theory: I have around 100 promises which I make in start and then later resolve them using Promise.all(). Each of those 100 promises in turn make some async REST calls whose respo

Solution 1:

Question: Question is can such a race condition be hit described in theory above? If not, how is the theory flawed?

The answer is no, such a race condition can not occur in Javascript, because Javascript is single-threaded. (see: Concurrency Model and Event Loop on MDN)

This means that while one callback handler is working with the data (assuming that setting the counter is a synchronous operation, which += is), nothing can force it to "yield" its execution, the next handler can only run when the previous one has finished.

Post a Comment for "Progress Of Promises"