0.0.14 • Published 5 years ago

restricted-concurrent-actions v0.0.14

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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

0.0.14

5 years ago

0.0.13

6 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago