Last active
August 29, 2015 14:09
-
-
Save chrisbolin/2c55af3fd1463bd0633e to your computer and use it in GitHub Desktop.
Firebase Work Queue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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