@krlwlfrt/async-pool
v1.0.0
Published
Async pool for iterables
Downloads
2,184
Readme
@krlwlfrt/async-pool
This is a TypeScript enabled version of tiny-async-pool.
Usage
import {asyncPool} from '@krlwlfrt/async-pool/lib/async-pool';
// can be anything that is iterable (aka implements Iterable)
const inputIterable = [100, 200, 300, 400];
/**
* Multiply input number by two
*
* @param item Number to multiply by two
*/
async function iteratorFunction (item: number): Promise<number> {
return item * 2;
}
// invoke async pool with limit 2 - meaning 2 iterator functions are executed simultaneously
asyncPool(2, inputIterable, iteratorFunction).then((result) => {
console.log(result); // outputs [ 200, 400, 600, 800 ]
});
Documentation
See online documentation for detailed API description.