1.0.1 • Published 4 years ago
@exan/timing-service v1.0.1
Timing service
A simple library to make events fire on a regular timer allowing you to time your code execution
Event firing is based on a startdate which is by default 00:00:00.000 UTC. This way, if you schedule an event to fire every 30 minutes and start the program at 11:13
, the first event will fire at 11:30
, second event will be fired at 12:00
and so on.
Usage
const timingService = require('@exan/timing-service')
let timer = new timingService.TimingService();
let unit = 'ms'; # 'ms', millisecond | 's', second | 'm', minute | 'h', hour | 'd', day
let amount = 1500; # how many of the unit
let eventName = 'myEvent'; # the event to be fired
# .setUTCHours on starting date, in this case the timer would start at 01:15:30.500 UTC
let startAt = [1, 15, 30, 500]; # optional, default is [0, 0, 0, 0]
timer.addEvent(unit, amount, eventName, startAt);
timer.on('myEvent', () => {
console.log('This will run every 1500 milliseconds \o/');
});