async-throttle
Throttle asynchronous Promise-based tasks
Last updated 9 years ago by tootallnate .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install async-throttle 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.0                                ...           latest (9 years ago)

3 Versions

  • 1.1.0                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.0.1                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 4
Last Month 1
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |