1.0.0 • Published 3 years ago

@evandrolg/thequeue v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

thequeue · license

Easy way to queue delayed callbacks. Designed to be used on both client and server-side.

Install

To install thequeue, execute:

$ npm install @evandrolg/thequeue

or

$ yarn add @evandrolg/thequeue

Usage

thequeue was designed to call functions that need to be invoked at a given time (e.g tracking functions that should be performed at a given time for performance reasons). Its api is quite simple, as the example below shows:

import thequeue from 'thequeue';

const q = thequeue();

const fn1 = () => console.log('fn1');
q.register(fn1);

const fn2 = () => console.log('fn2');
q.register(fn2);

const fn3 = () => console.log('fn3');
q.register(fn3);

q.start();
// the functions will be called in the order in which they were added to the queue.

thequeue was also designed with performance in mind and all registered functions are in a Queue that was implemented using a LinkedList. This means that the functions are registered in constant time and are processed (when the start method is invoked) in linear time, without adding any extra space in memory.

TODO

  • Add option to allow a function to be called only when the previous one has finished