timeout-percentage
Similar to setTimeout
, but periodically reports what percentage of the time has elapsed.
For example, for a timeout value of 1000ms
, you can set 10
intervals, each 100ms
, where you get a callback which reports the elapsed time in percentage. This is useful for creating progress bars.
You can also cancel the timeout before it ends.
Update: Now it can be called multiple times in parallel to setup multiple parallel timeouts.
Install
npm i -s timeout-percentage
Usage
const tp = ; { console;} { console;} let options = intervalCallback: intervalCallback // Will be called at each interval intervalEndCallback: intervalEndCallback // Will be called at the end of the timeout totalTimeout: 1000 // Total timeout in ms numberOfIntervals: 10 // Number of intervals; startoptions; /*Output: 10% done.20% done.30% done.40% done.50% done.60% done.70% done.80% done.90% done.100% done.Interval finished!*/
See test/test.js for more examples.
Cancelling the timer
You can cancel a timer that is still running:
let myTimer = startoptions;;