Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Limits the number of function to be called at the same time.
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
README.md
limit.js
package.json
test.js

README.md

Limit

Limits the number of function to be called at the same time.

var len = 8

for (var i = 0; i < len; i++) {
  limit(i, function(index, release) {
    console.log('#' + index);
  })
};

// #0
// #1
// #2
// #3
// #4
// no message unless `release()`

Becase limit limits number of function to 5 by default, the index form 5 will not appear. So release it.

var len = 8

for (var i = 0; i < len; i++) {
  limit(i, function(index, release) {
    console.log('#' + index);
    setTimeout(function() {
      release()
    }, 20)
  })
};

// #0
// #1
// #2
// #3
// #4

// 20ms passed and then:
// #5
// #6
// #7
Something went wrong with that request. Please try again.