restricted-concurrent-actions
TypeScript icon, indicating that this package has built-in type declarations

0.0.14 • Public • Published

restricted-concurrent-actions

Like Promise.all, but limit number of concurrent promises

Requirements

  • Node.js ≥ 8.9.0

Usage

Function Signature

declare function restrictedConcurrentActions<Y> (
  actions: Iterable<() => Promise<Y>>,
  partLength: number,
  handleRemain?: (tray: Y[]) => Y[]
): AsyncIterableIterator<Y[]>

declare namespace restrictedConcurrentActions {
  declare function asArray<Y> (
    actions: Iterable<() => Promise<Y>>,
    partLength: number,
    handleRemain?: (tray: Y[]) => Y[]
  ): Promise<Y[][]>
}

Examples

Fetch 4 URLs at a time

import rca from 'restricted-concurrent-actions'
import fetch from 'node-fetch'

const resources = [ /* An array of URLs */ ]
const actions = resources.map(url => () => fetch(url))
const partLength = 4

const result = await rca.asArray(actions, partLength)
console.log(result)

License

MIT © Hoàng Văn Khải

Readme

Keywords

Package Sidebar

Install

npm i restricted-concurrent-actions

Weekly Downloads

0

Version

0.0.14

License

MIT

Unpacked Size

4.5 kB

Total Files

4

Last publish

Collaborators

  • khai96_