Tiny Promise Pool
A tiny library to execute multiple promises in parallel, keeping not to execute more than N promises at any one time, using a promise.
Install:
npm i tiny-promise-pool
Use with creator function:
var promisePool = { if index>=20 return null // no more return { }} var all = all
Result:
context: index: 0 thread: 0 data: 17 ended: 10 promise: Promise 17 result: 17 context: index: 1 thread: 1 data: 17 ended: 1 promise: Promise 19 result: 19 context: index: 2 thread: 2 data: 17 ended: 7 promise: Promise 21 result: 21 context: index: 3 thread: 0 data: 17 ended: 6 promise: Promise 23 result: 23 context: index: 4 thread: 1 data: 17 ended: 2 promise: Promise 25 result: 25 context: index: 5 thread: 2 data: 17 ended: 3 promise: Promise 27 result: 27 context: index: 6 thread: 0 data: 17 ended: 4 promise: Promise 29 result: 29 context: index: 7 thread: 1 data: 17 ended: 5 promise: Promise 31 result: 31 ... context: index: 19 thread: 1 data: 17 ended: 19 promise: Promise 55 result: 55
Use with array of promises:
{ return { }} const promiseList =
Using generator to generate promises:
{ for var i=0; i<10; i+=1 ... } const pool =
Nested promise pools:
const innerPool = const pool = pool
Debugging tool:
promisePool = visualize = const pool = pool
TODO list:
- API similar to Promise.all(): "Promise.pool([promise, ...], threads)"
- options for behavior on reject:
- reject as soon as one is rejected (same as Promise.all)
- wait for all to resolve even if some are rejected (same as Promise.when)
- support listeners for individual promise completions/rejections
migration from previous versions:
the following option keys are renamed:
- next_promise_data -> context_data
- next_promise -> promises
- max_parallel -> threads
you can still use the older option keys, but they are deprecated