async-throttle

让节流变得简单、轻松、异步。「Throttling made simple, easy, async.」

  • Owner: zeit/async-throttle
  • Platform:
  • License:: GNU General Public License v2.0
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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.

// 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

Main metrics

Overview
Name With Ownerzeit/async-throttle
Primary LanguageMakefile
Program languageJavaScript (Language Count: 1)
Platform
License:GNU General Public License v2.0
所有者活动
Created At2014-05-29 20:43:16
Pushed At2024-01-29 13:34:54
Last Commit At2024-01-29 11:00:48
Release Count3
Last Release Name (Posted on 2014-09-29 13:01:33)
First Release Name (Posted on 2014-09-29 13:01:33)
用户参与
Stargazers Count172
Watchers Count9
Fork Count15
Commits Count26
Has Issues Enabled
Issues Count2
Issue Open Count0
Pull Requests Count4
Pull Requests Open Count1
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private