Scenario
I have a Node.JS service (written using ExpressJS) that accepts image uploads via DnD (example). After an image is uploaded, I do a few thi
For anyone who thought Brandon's quick-and-dirty might be too quick-and-dirty, here's a variation that is no longer and doesn't have the unnecessary busy-wait. I'm not in a position to test it but it should work.
var enqueue = function() {
var queue = [];
var execImmediate = function(fImmediate) {
enqueue = function(fDelayed)
queue.push(fDelayed);
};
fImmediate();
var ic = setInterval(function() {
var fQueued = queue.shift();
if (fQueued) {
fQueued();
} else {
clearInterval(ic);
enqueue = execImmediate;
}
}, 1000);
};
return execImmediate;
}();