Skip to content

Instantly share code, notes, and snippets.

@Raynos Raynos/queue.js
Created Dec 31, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.