Created
October 26, 2015 23:59
-
-
Save balanza/2bf0ac043db55091a6fd to your computer and use it in GitHub Desktop.
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
//the buffer to store measures | |
var buffer = []; | |
//this is the function that calls the endpont | |
var saveToAPI = function(data){ | |
//here the logic fo calling the endpoint | |
}; | |
//this is the function that handles data receiving | |
// it passes data from the buffer to the api, then clean the buffer | |
// note the _.debounce() function: it postpones the execution of 3000ms. | |
// In that period, no more then one execution is allowed, that is every other call is ignored | |
var save = _.debounce(function(){ | |
saveToAPI(buffer); | |
buffer = []; | |
}, 3000); | |
//this is the event from the sensor | |
sensor.addEvenListener('measure', save); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment