A circule buffer for firebase. Elements are dequeued and enqueue, and a callback function is run on their dataSnapshot.
Last active
August 29, 2015 14:08
-
-
Save chrisbolin/742d8578daf6aa729629 to your computer and use it in GitHub Desktop.
Firebase Circular Buffer
This file contains 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
var fbRef = new Firebase('https://yourapp.firebaseio.com'); | |
var bufferRef = fbRef.child('path/to/buffer'); | |
function getNext(callback){ | |
// get single-element list, [x] | |
bufferRef.startAt().limit(1).once('value',function(listSnap){ | |
// get element, x | |
listSnap.forEach(function(elementSnap){ | |
// remove x | |
elementSnap.ref().remove(function(error){ | |
// if no error, place back | |
if (!error){ | |
// push x to end | |
bufferRef.push(elementSnap.val()); | |
// exec callback functions | |
callback(elementSnap); | |
} | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment