Socket
Book a DemoInstallSign in
Socket

@remy/promise-throttle

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@remy/promise-throttle

Throttles promises being executed, i.e. to allow no more than 10 at a time

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

promise-throttle

Throttles promises to n concurrent promises at a time.

Usage

// run 10 promises at a time
var throttle = require('promise-throttle')(10);
var request = require('request');
var urls = [...];

var promises = urls.map(function (url) {
  return throttle(function (resolve, reject) {
    request(url, function (error, res, body) {
      if (error) {
        return reject(error);
      }

      if (res.statusCode === 200) {
        return resolve(body);
      } else {
        return reject(new Error(body)); // likely error too
      }
    });
  });
});

Promise.all(promises).then(function (requestData) {
  // requestData contains all the response data
  // limiting to 10 concurrent requests at a time.
});

Keywords

throttle

FAQs

Package last updated on 31 Jul 2015

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