promise-call-limit

WebJar for promise-call-limit

License

License

ISC
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

promise-call-limit
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

promise-call-limit
WebJar for promise-call-limit
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/isaacs/promise-call-limit

Download promise-call-limit

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/promise-call-limit/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>promise-call-limit</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/promise-call-limit/
implementation 'org.webjars.npm:promise-call-limit:1.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/promise-call-limit/
implementation ("org.webjars.npm:promise-call-limit:1.0.1")
'org.webjars.npm:promise-call-limit:jar:1.0.1'
<dependency org="org.webjars.npm" name="promise-call-limit" rev="1.0.1">
  <artifact name="promise-call-limit" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='promise-call-limit', version='1.0.1')
)
libraryDependencies += "org.webjars.npm" % "promise-call-limit" % "1.0.1"
[org.webjars.npm/promise-call-limit "1.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

promise-call-limit

Call an array of promise-returning functions, restricting concurrency to a specified limit.

USAGE

const promiseCallLimit = require('promise-call-limit')
const things = getLongListOfThingsToFrobulate()

// frobulate no more than 4 things in parallel
promiseCallLimit(things.map(thing => () => frobulateThing(thing)), 4)
  .then(results => console.log('frobulated 4 at a time', results))

API

promiseCallLimit(queue Array<() => Promise>, limit = defaultLimit)

The default limit is the number of CPUs on the system - 1, or 1.

The reason for subtracting one is that presumably the main thread is taking up a CPU as well, so let's not be greedy.

Note that the array should be a list of Promise-returning functions, not Promises themselves. If you have a bunch of Promises already, you're best off just calling Promise.all().

The functions in the queue are called without any arguments.

Versions

Version
1.0.1