Skip to content

Instantly share code, notes, and snippets.

@rynomad
Created February 24, 2014 06:58
Show Gist options
  • Save rynomad/9183135 to your computer and use it in GitHub Desktop.
Save rynomad/9183135 to your computer and use it in GitHub Desktop.
var proc = {}
module.exports = proc;
var msCh = new MessageChannel()
var queue = [];
msCh.port1.onmessage = function(ev) {
var source = ev.source;
if ( ev.data === 'proc-tick') {
if (queue.length > 0) {
var fn = queue.shift();
fn();
}
}
}
proc.nextTick = function nextTick(fn) {
queue.push(fn);
msCh.port2.postMessage('proc-tick');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment