3.2.0 • Published 8 years ago

now-or-again v3.2.0

Weekly downloads
9
License
ISC
Repository
github
Last release
8 years ago

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
3.2.0

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.0.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago