Détail du package

async-throttle

zeit135kMIT1.1.0

Throttle asynchronous Promise-based tasks

readme

async-throttle

Build Status XO code style Slack Channel

Throttling made simple, easy, async.

How to use

This example fetches the <title> tag of the supplied websites, but it processes a maximum of two at a time.

// deps
const fetch = require('node-fetch')
const createThrottle = require('async-throttle')
const cheerio = require('cheerio').load

// code
const throttle = createThrottle(2)
const urls = ['https://zeit.co', 'https://google.com', /* … */]
Promise.all(urls.map((url) => throttle(async () => {
  console.log('Processing', url)
  const res = await fetch(url)
  const data = await res.text()
  const $ = cheerio(data)
  return $('title').text()
})))
.then((titles) => console.log('Titles:', titles))

To run this example:

git clone git@github.com:zeit/async-throttle
cd async-throttle
npm install
npm run example

changelog

1.1.0 / 2016-10-26

  • [5bf754037e] - add retrospection test case (Nathan Rajlich)
  • [61efd5a93a] - keep copies of the "state" for retrospection (Nathan Rajlich)
  • [0add37762e] - fix xo lint (Nathan Rajlich)

1.0.0 / 2016-10-26

  • [c7e66cd089] - refactor / simplify logic (Nathan Rajlich)
  • [3069aee584] - Uppercase readme (Leo Lamprecht)
  • [d746fed580] - Badge for slack and XO (Leo Lamprecht, #6)
  • [5d524fade1] - Migrate linting from standard to XO (Jeroen Engels)
  • [74cef15674] - concise refactor (#2) (Charles Renwick)
  • [596dc23b4a] - Readme: add Travis-CI build badge (Nathan Rajlich)
  • [7e6449c59c] - add .travis.yml file (Nathan Rajlich)
  • [58b3f955de] - add "use strict" statement (Nathan Rajlich)
  • [da922b17c2] - Fix async-node example (Charles Renwick, #1)
  • [57e82b0971] - package: add "test" script (Nathan Rajlich)

0.0.1 / 2016-09-30