Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created December 31, 2012 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Raynos/4422304 to your computer and use it in GitHub Desktop.
Save Raynos/4422304 to your computer and use it in GitHub Desktop.
function Queue(action) {
var buffer = []
return push
function push(data) {
buffer.push(data)
if (buffer.length === 1) {
action(buffer[0], next)
}
}
function next() {
buffer.shift()
if (buffer.length > 0) {
action(buffer[0], next)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment