co-limiter
Limits how many generators can be ran at the same time
Last updated 3 years ago by mvila .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install co-limiter 
SYNC missed versions from official npm registry.

co-limiter Build Status

Limits how many generators can be ran at the same time.

Installation

In your project folder, type:

npm install co-limiter

Example

Let's run 10 jobs with a maximum concurrency of 2:

var co = require('co');
var wait = require('co-wait');
var limiter = require('co-limiter');

var limit = limiter(2);

var job = function *() {
  console.log('Doing something...');
  yield wait(1000);
}

for (var i = 0; i < 10; i++) {
  co(function *() {
    yield limit(job());
  })();
}

The loop duration will be 5 seconds.

API

limiter(concurrency)

Return a limit function with the specified concurrency.

limit(generator, [priority])

Yield the specified generator. If the maximum concurrency is reached, wait until a slot becomes available. You can optionally specify the priority parameter if you want to prioritize certain generators.

License

MIT

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 4
Dependencies (2)
Dev Dependencies (1)

Copyright 2014 - 2017 © taobao.org |