zeit/async-throttle

Name: async-throttle

Owner: ZEIT

Description: Throttling made simple, easy, async.

Created: 2016-09-30 19:19:33.0

Updated: 2018-05-15 01:00:31.0

Pushed: 2017-10-30 13:02:24.0

Homepage:

Size: 16

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

async-throttle

Note: this project has been deprecated in favor of the smaller, more efficient and more zeit/async-sema. This project works and is well-tested, but we no longer favor it at ZEIT.

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.

eps
t fetch = require('node-fetch')
t createThrottle = require('async-throttle')
t cheerio = require('cheerio').load

ode
t throttle = createThrottle(2)
t urls = ['https://zeit.co', 'https://google.com', /* ? */]
ise.all(urls.map((url) => throttle(async () => {
nsole.log('Processing', url)
nst res = await fetch(url)
nst data = await res.text()
nst $ = cheerio(data)
turn $('title').text()

n((titles) => console.log('Titles:', titles))

To run this example:

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

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.