Html: Limit queueMicrotask repetitive execution

Created on 19 May 2019  路  2Comments  路  Source: whatwg/html

Repetitive tasks execution preventing from anything else to be executed, since there is always a new task to execute in the micro tasks queue.

Such scenario should be prevented.

Loop Code :

let c = 0;
function runTask(){
 queueMicrotask(() => {
        try {
            console.log(c++);
            runTask();
        } catch (e) {
            //Expected some error here
        }
    });
}
runTask();
clarification event loop

Most helpful comment

This was discussed when the API was added: https://github.com/whatwg/html/issues/512#issuecomment-171498578

In reality this really isn't too different from having a script do while (true) {}. The HTML Standard already has provisions against both of these cases in https://html.spec.whatwg.org/multipage/webappapis.html#killing-scripts

All 2 comments

afaik some browsers already silently do this.

This was discussed when the API was added: https://github.com/whatwg/html/issues/512#issuecomment-171498578

In reality this really isn't too different from having a script do while (true) {}. The HTML Standard already has provisions against both of these cases in https://html.spec.whatwg.org/multipage/webappapis.html#killing-scripts

Was this page helpful?
0 / 5 - 0 ratings

Related issues

travisleithead picture travisleithead  路  4Comments

NE-SmallTown picture NE-SmallTown  路  3Comments

empijei picture empijei  路  3Comments

NE-SmallTown picture NE-SmallTown  路  4Comments

benjamingr picture benjamingr  路  3Comments