New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

call-limit

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

call-limit

Limit the number of simultaneous calls to an async function

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
127K
increased by5.84%
Maintainers
1
Weekly downloads
 
Created
Source

call-limit

Limit the number of simultaneous executions of a async function.

const fs = require('fs')
const limit = require('call-limit')
const limitedStat = limit(fs.stat, 5)

Or with promise returning functions:

const fs = Bluebird.promisifyAll(require('fs'))
const limit = require('call-limit')
const limitedStat = limit.promise(fs.statAsync, 5)

USAGE:

Given that:

const limit = require('call-limit')

limit(func, maxRunning) → limitedFunc

The returned function will execute up to maxRunning calls of func at once. Beyond that they get queued and called when the previous call completes.

func must accept a callback as the final argument and must call it when it completes, or call-limit won't know to dequeue the next thing to run.

By contrast, callers to limitedFunc do NOT have to pass in a callback, but if they do they'll be called when func calls its callback.

limit.promise(func, maxRunning) → limitedFunc

The returned function will execute up to maxRunning calls of func at once. Beyond that they get queued and called when the previous call completes.

func must return a promise.

limitedFunc will return a promise that resolves with the promise returned from the call to func.

limit.method(class, methodName, maxRunning)

This is sugar for:

class.prototype.methodName = limit(class.prototype.methodName, maxRunning)

limit.method(object, methodName, maxRunning)

This is sugar for:

object.methodName = limit(object.methodName, maxRunning)

For example limit.promise.method(fs, 'stat', 5) is the same as fs.stat = limit.promise(fs.stat, 5).

limit.promise.method(class, methodName, maxRunning)

This is sugar for:

class.prototype.methodName = limit.promise(class.prototype.methodName, maxRunning)

limit.promise.method(object, methodName, maxRunning)

This is sugar for:

object.methodName = limit.promise(object.methodName, maxRunning)

For example limit.promise.method(fs, 'statAsync', 5) is the same as fs.statAsync = limit.promise(fs.statAsync, 5).

FAQs

Package last updated on 03 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc