0.0.14 • Published 4 years ago

restricted-concurrent-actions v0.0.14

Weekly downloads
3
License
MIT
Repository
github
Last release
4 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

4 years ago

0.0.13

5 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago