JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 287
  • Score
    100M100P100Q91747F
  • License MIT

Tiny ES6 class to run functions after a given delay. Uses just on timer at any time and setImmediate to launch

Package Exports

  • fun-dispatcher

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fun-dispatcher) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

codecov

fun-dispatcher

Tiny ES6 class to run functions after a given delay. Uses just one timer at any time and setImmediate to execute functions.

Written in Typescript, 100% test coverage, targeting current LTS Node.JS

Example:

const { Scheduler } = require('fun-dispatcher');

const fd = new Scheduler();

fd.schedule('task1', () => { console.log('Will run after about 600ms') }, 600);
fd.schedule('task2', () => {
    console.log('Tasks can be cancelled by id');
    fd.delete('task1')
}, 400)

// can forcefully execute all tasks
fd.flush();
// or just next task in line waiting for be executed
fd.runNext()

// Scheduler extends native Map class, so, all methods are available
// like .delete to unschedule task or iteration
for (const [task, { delay }] of fd) {
    console.log('Task `%s` was scheduled with original delay of %d ms', task, delay);
}