call-limit
Limit the number of simultaneous calls to an async function
Last updated 6 years ago by iarna .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install call-limit 
SYNC missed versions from official npm registry.

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).

Current Tags

  • 1.1.1                                ...           latest (6 years ago)

6 Versions

  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |