Skip to content

Instantly share code, notes, and snippets.

@balanza
Created October 26, 2015 23:59
Show Gist options
  • Save balanza/2bf0ac043db55091a6fd to your computer and use it in GitHub Desktop.
Save balanza/2bf0ac043db55091a6fd to your computer and use it in GitHub Desktop.
//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