项目作者: EvandroLG

项目描述 :
:clock130: Easy way to queue delayed callbacks
高级语言: TypeScript
项目地址: git://github.com/EvandroLG/thequeue.git
创建时间: 2021-04-16T10:16:10Z
项目社区:https://github.com/EvandroLG/thequeue

开源协议:MIT License

下载


thequeue · BuildStatus license

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

Install

To install thequeue, execute:

  1. $ npm install @evandrolg/thequeue

or

  1. $ 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:

  1. import thequeue from 'thequeue';
  2. const q = thequeue();
  3. const fn1 = () => console.log('fn1');
  4. q.register(fn1);
  5. const fn2 = () => console.log('fn2');
  6. q.register(fn2);
  7. const fn3 = () => console.log('fn3');
  8. q.register(fn3);
  9. q.start();
  10. // the functions will be called in the order in which they were added to the queue.

thequeue was also developed 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