A singleton for pulse set (interval set)
- Easy to manage all the intervals in one place
- It's more convenient to manage all the interval cache by name than id
- Use setTimeout instead of setInterval so can stop the interval only return false in the action
- Enable to catch the exception
import PS from 'pulse-set.js';
PS.start('pulse', 1000, () => {
console.log('Trigger an action');
},
() => {
console.log('error');
}
);
PS.end('pulse');
PS.start(name, time, action, error) - Start and cache a pulse
name
{string} Pulse nametime
{int} Pulse timestampaction
{function} Pulse actionerror
{function} Emit when exception occures in action running
PS.end(name) - End and remove the pulse
name
{string} Pulse name