distribute-js
v3.0.1
Published
Distribute anonymous function executions over a defined timespan
Downloads
7
Readme
DistributeJs
Distribute anonymous function executions over a defined timespan
Install
$ npm i -S distribute-js
Usage
const Distribution = require('distribute-js');
const collection = new Distribution();
collection.add(() => {
console.log(1);
});
collection.add(() => {
console.log(2);
});
const promise = distribution.in(2000).run();
promise.resolve((distribution) => {
console.log(distribution);
});
API
Methods
add(callable)
Method to add a new function to the stack.
Arguments
| Argument | Type | Description |
|---|---|---|
| callable | Function
| Function to be added to the execution stack. |
in(timespan)
Method to set the timespan in which all functions should be executed.
Arguments
| Argument | Type | Description |
|---|---|---|
| timespan | Number
| Timespan in milliseconds. |
run()
Method to execute the call stack. Returns a Promise.
License
GPL-2.0 © Willi Eßer