Countdownjs is able to fire an event after a defined delay. Its main goal is being able to tell you at anytime, how many time you still need to wait for your event to be fired.
In a perfect JS world, this library shouldn't exist.
It has been developed since we can't trust the private properties _idleStart
and _idleTimeout
returned by setTimeout anymore (in node v3 anyway)
delay
: time is ms to wait before calling the handler (required)handler
: function to execute when the delay is elapsed (default to empty function)options
restart
: boolean, set to true if you want your countdown to restat automatically when the delay is elapsed (default to false).frame
: Time in ms, specify how many time you want to wait to refresh the countdown, more this value will be low, more the countdown will be accurate (default to 1000).
Start the timer.
Stop the timer.
Stop the timer and reset the countdown to its initial value.
Reset then start again.
Return the remaining time in ms.
Return the time left in ms.
Reset then start again.
const Countdown = require('contdownjs');
const countdown = new Countdown(5000, function() { console.log('Hello World'); });
countdown.start(); // It will print "Hello World" after 5s
// Some async task that take we do not know exactly how many time ...
countdown.getRemainingTime(); // 3000 for exemple
npm install
npm test