npm.io
1.0.2 • Published 9 years ago

func-pool

Licence
MIT
Version
1.0.2
Deps
0
Vulns
0
Weekly
0
Stars
2

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