Answer the question
In order to leave comments, you need to log in
JS Event Loop, is it possible to block?
Hello.
The situation is the following. In the browser, asynchronous logic (as far as I understand) is implemented using the Event Loop, i.e. all calls, incl. delayed ones (timeouts, XHR, etc.) fall into one common browser stack, which is sequentially called by the browser. Thus, from the client side, we can implement asynchronous logic, but in fact for the browser this is one common call flow.
What happens if the function does not return a response in this stack, and the browser considers that it is executing indefinitely? Will the browser make function calls, send events to JS, etc. further down the stack?
Real case: Implementing browser plugins that provide a JS API, and functions from that API may not return a response (synchronously) for a very long time. How should the browser behave in this case?
Answer the question
In order to leave comments, you need to log in
I'm not well versed in this. But it looks like this link should help you.
Or even here .
The question is not very clear. What about asynchronous functions?
1. Let's say you have a function that calculates the number Pi up to a trillion digits (well, in general, any function with very heavy calculations).
2. Let's say you want to execute this function only when the user has pressed the button.
3. As a result, you will get that the call to this function will be inserted into the execution stack only after an indefinite time in the future.
4. But when it is already inserted (after a click), then it will hang the computer, because it is synchronous in itself.
The only way to do heavy calculations asynchronously is to put them in a Web Worker
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question