promise.map
v0.5.0
Published
Promise.map
Downloads
6,564
Readme
promise.map
Promise.map
Install
$ npm i -S promise.map
API
pmap
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
)
map on Workers: pmapWorker
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[]>
Why
- 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
See Also
Changelog
License
the MIT License http://magicdawn.mit-license.org