Skip to content

Instantly share code, notes, and snippets.

@watson
Last active January 3, 2016 06:09
Show Gist options
  • Select an option

  • Save watson/8420602 to your computer and use it in GitHub Desktop.

Select an option

Save watson/8420602 to your computer and use it in GitHub Desktop.
Thinking about the most simple queueing implementation...
var process = function (a, b) {
// do some async stuff with a and b
};
process(foo1, bar1);
process(foo2, bar2);
var queue = [];
var processNext = function () {
var a = queue[0][0],
b = queue[0][1];
// do some async stuff with a and b
queue.shift();
if (queue.length > 0)
process.nextTick(processNext);
};
var prepare = function () {
queue.push(arguments);
if (queue.length === 1)
process.nextTick(processNext);
};
prepare(foo1, bar1);
prepare(foo2, bar2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment