Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Created November 19, 2014 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhoff/5a911b5cc9f2e500cc10 to your computer and use it in GitHub Desktop.
Save alanhoff/5a911b5cc9f2e500cc10 to your computer and use it in GitHub Desktop.
Rodar apenas uma vez
var rodando = false;
var minhaFunc = function(){
if(rodando)
return; // Já está rodando
rodando = true;
db.query('select 1 + 1 as result', function(err, result){
rodando = false;
if(err)
throw err;
console.log(result);
});
};
// Rodar essa função a cada segundo
setInterval(minhaFunc, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment