Skip to content

Instantly share code, notes, and snippets.

@chrisbolin
Last active August 29, 2015 14:09
Show Gist options
  • Save chrisbolin/2c55af3fd1463bd0633e to your computer and use it in GitHub Desktop.
Save chrisbolin/2c55af3fd1463bd0633e to your computer and use it in GitHub Desktop.
Firebase Work Queue
// ref.transaction() can be used in place of ref.set()
queueChildRef.transaction(function(theItem) {
dataToProcess = theItem;
if(theItem) {
return null; // if there is still a value, delete it and claim job
} else {
return; // if there is not a value, abort transaction. job already claimed
}
}, function(error, committed, snapshot, dummy) {
if (error) throw error;
if(committed) {
console.log("Claimed a job.");
} else {
console.log("Another worker beat me to the job.");
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment