JSFiddle - React, Tailwind, and code Playground

by blesh

JavaScript

//Purely functional queue. Self-executing.

var funcQueue = (function (){
    var q = []
    
    return function(fn) {
        if(q.length === 0) {
            fn();
            setTimeout(function(){
                var next = q.shift();
                if(next) next();
            },0);
        } else {
            q.push(fn);
        }
    };
})();

setTimeout(function (){
    funcQueue(function (){
        console.log('WEEEEEEE');
    });
}, 0);
funcQueue(function(){ 
    var x = 0;
    for(var i = 10000000000; i--;) {
        x += i;
    }
    console.log('done', x);
});