Relative Content

Tag Archive for javascriptasynchronouspromise

Why don’t we use recursive functions instead of promises?

I’m trying to grasp the concept of asynchronous JS and in it there’s this concept of promises, something used to escape nested call stacks. A call stack I just feel like this can be done much better if recursive functions are used. RF function calls can be altered, and we only need to be careful that we don’t accidentally run the recursive function to infinity.

Code executing inside of promise declarations at first instead of waiting for promise race

I have piece of code here where I have used Promises to make use the a timeout function resolves after 1 min if the reload function takes more than 1 min to execute, the problem I am facing is the code is entering the promise declarations initially and executing everything internally one by one. (Its hitting setTimeout first and later reload() and then finally promise.race). It should actually hit promise.race first and execute 2 promises simultaneously later. How to refactor this.