1.0.2 • Published 7 years ago

func-pool v1.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

func-pool

Build Status Coverage Status npm version Total downloads PRs Welcome MIT Licence

Execute functions sequentially and modify (add, delete, sort) the order of execution when needed

Install

npm i func-pool

Quick Examples

import FuncPool from 'func-pool';
const funcPool = new FuncPool();

function hello() { console.log('hello'); }
function goodbye() { console.log('goodbye'); }

funcPool.autoRun([hello, goodbye]);
funcPool.update();
// print 'hello'
// print 'goodbye'

funcPool.removeFromAutoRun(goodbye);
funcPool.update();
// print 'hello'

funcPool.autoRun(goodbye);
funcPool.update();
// print 'goodbye'
// print 'hello'

funcPool.clear();
funcPool.update();
// print nothing

Methods

autoRun(Function | Array\<Function>)

autoRun accept a function or an array of functions and will add to the update queue

removeFromAutoRun(Function | Array\<Function>)

removeFromAutoRun accept a function or an array of functions and will remove the corresponding method from the update queue

update(): Promise\<Array>

Call the update method will call the function in the queue in sequence and return a Promise Object

clear()

clear update queue