now-or-again

3.2.0 • Public • Published

Run a function now, or if its already running (callback hasn't returned) then run it again when it finishes. Will only call the function one additional time even if you call nowOrAgain several times while the function is working.

Usage

const nowOrAgain = require('now-or-again');
let count = 1;
 
function update(n, cb) {
  console.log('updating', n);
  setTimeout(cb, 1000);
}
 
nowOrAgain(update,1);
nowOrAgain(update,2);
nowOrAgain(update,3);
nowOrAgain(update,4);
setTimeout(()=>nowOrAgain(update,5),500);
setTimeout(()=>nowOrAgain(update,6),1001);

Output:

updating 1
updating 5
updating 6

Readme

Keywords

none

Package Sidebar

Install

npm i now-or-again

Weekly Downloads

9

Version

3.2.0

License

ISC

Last publish

Collaborators

  • runvnc