How to abort JavaScript async functions? -


For example, you have a web music player app when a user clicks the play button, then a fire Is looking for MP3 data, installation of player etc., but then the user changes his mind and clicks on another track, is there any way to completely cancel the previous function? I know that you can end XHRequests, but I mean that the entire function might be JS promise?

A synchronous function in JavaScript will run to complete. It will not be interrupted by any other user action. Therefore, if any function in your scenario sets fire to the player and the player is set, then that function will be run to complete before proceeding to the next user event. Therefore, you can not stop a synchronization function in Javascript and there will be no way anyway (except the web audience that we are not discussing here), javascript is a single thread, until the function is turned on , Will run it to complete and no other user event will be processed.

If, however, that function contains some kind of asynchronous operation (such as loading ajax or a player loading a music file), even if the async operation can be aborted that operation It is completely dependent on specific support in - There is no general stop to help us with asynchronous details, you have to disclose your actual code so that we can see what you do are doing.

Promises there is no device to abort the asynchronous tasks. In fact, they are somewhat of an instrument for the opposite because they report when and what happened when the asynchronous operation happened. They do not cause them to happen, inform observers when there are some things from asynchronous actions.


Normally in the case of stack overflow questions, we can help in more depth if you disclose your actual code because it will convert your question from the theoretical discussion into a real analysis. , Which are the options for your actual code.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -