limited-map

0.0.1 • Public • Published

limited-map

Async map function with limited concurrency for JavaScript. This is a replacement for Promise.all(items.map(asyncCallback)). For example, this is useful if you have an API that you don't want to overload with your request flood.

Example

const limitedMap = require("limited-map");
 
async function fetchDocs() {
  const docs = await limitedMap(urls, url => getJSON(url), 30);
  return docs;
}

API

limitedMap<T, U>(
  items: Array<T>, 
  callback: (item: T, index: number, array: Array<T>) => Promise<U>, 
  concurrency: number
): Promise<Array<U>>

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i limited-map

      Weekly Downloads

      1

      Version

      0.0.1

      License

      MIT

      Unpacked Size

      3.61 kB

      Total Files

      5

      Last publish

      Collaborators

      • normanrz