Promise.map
$ npm i -S promise.map
declare function pmap<IN, OUT>(
arr: IN[],
fn: (item: IN, index: number, arr: IN[]) => Promise<OUT> | OUT,
concurrency: number,
): Promise<OUT[]>
declare namespace pmap {
export function pmapWorker<IN, OUT, AnyWorker extends Object>(
arr: IN[],
fn: (item: IN, index: number, arr: IN[], worker: AnyWorker) => Promise<OUT>,
workers: AnyWorker[],
): Promise<OUT[]>
}
export = pmap
var p = pmap(
arr,
function (item, index, arr) {
return getOtherPromise(item)
},
concurrency,
)
for cpu heavy work, you can map on workers (WebWorker / Node.js worker_threads)
export function pmapWorker<IN, OUT, AnyWorker extends Object>(
arr: IN[],
fn: (item: IN, index: number, arr: IN[], worker: AnyWorker) => Promise<OUT>,
workers: AnyWorker[],
): Promise<OUT[]>
- bluebird is awesome, and provide tons of convience methods, such as Promise.map, it provides
async.parallelLimit
but, it got some opinioned ways, like this warn. So we'd better split things out. - package
promise-map
simply useArray.prototype.map
, that lost aconcurrency
orparallelLimit
control - earlier than p-map
the MIT License http://magicdawn.mit-license.org