⚖️ Limit an async function's concurrency with ease!

Overview

limit-concur

Limit an async function's concurrency with ease!

Install

$ npm i limit-concur

Usage

import got from 'got'
import limitConcur from 'limit-concur'

const categories = await got(
  `https://api.chucknorris.io/jokes/categories`
).json()

async function getChuckNorrisJoke(category) {
  const { value } = await got(`https://api.chucknorris.io/jokes/random`, {
    searchParams: {
      category
    }
  }).json()
  return value
}

const limitedGetChuckNorrisJoke = limitConcur(4, getChuckNorrisJoke)

// At most 4 requests are pending at any given time!
const jokes = await Promise.all(categories.map(limitedGetChuckNorrisJoke))
console.log(jokes)
//=> [
//     'Chuck Norris once rode a nine foot grizzly bear through an automatic car wash, instead of taking a shower.',
//     "Chuck Norris is actually the front man for Apple. He let's Steve Jobs run the show when he's on a mission. Chuck Norris is always on a mission.",
//     "Bill Gates thinks he's Chuck Norris. Chuck Norris actually laughed. Once.",
//     'Chuck Norris can install iTunes without installing Quicktime.',
//     ...
//   ]

You can get an API equivalent to p-limit like so:

import limitConcur from 'limit-concur'

const limit = limitConcur(1, fn => fn())

const input = [
  limit(() => fetchSomething(`foo`)),
  limit(() => fetchSomething(`bar`)),
  limit(() => doSomething())
]

const result = await Promise.all(input)
console.log(result)
//=> [ ..., ..., ... ]

Contributing

Stars are always welcome!

For bugs and feature requests, please create an issue.

For pull requests, please read the contributing guidelines.

License

Apache 2.0

This is not an official Google product.

You might also like...

▶ A tool that helps developers to translate JSON to different languages with ease

▶ A tool that helps developers to translate JSON to different languages with ease

JSON translator Link 🔗 : https://json-translator.vercel.app/ 👉 The information you have entered will not be kept on this site. 👉 Translation is usi

Mar 6, 2022

Showcase your skills on your Github readme or resumé with ease ✨

Showcase your skills on your Github readme or resumé with ease ✨

Showcase your skills on your GitHub or resumé with ease! Powered by Cloudflare Workers ⚡ Docs Example Specifying Icons Themed Icons Icons Per Line Cen

Dec 31, 2022

A Technical Blogging Website that utilizes Notion as a CMS for ease of modification with the help of the notion-API & whose content has been rendered with next-js and react-notion-x

A Technical Blogging Website that utilizes Notion as a CMS for ease of modification with the help of the notion-API & whose content has been rendered with next-js and react-notion-x

GDSC MCE Blogs This repo is what GDSC MCE uses to power their blogging website gdsc-mce-blogs. It uses Notion as a CMS, fetching content from Notion a

Dec 16, 2022

HanAssist - Utilities to ease Chinese variant handling in user scripts and gadgets.

HanAssist 代码文档 HanAssist 是帮助中文维基百科及其他 MediaWiki 网站上的用户脚本和小工具更优雅地处理中文变体消息的实用程序。 本程序的目标是取代wgULS()和wgUVS()小工具。 HanAssist.localize( { hans: '一天一苹果,医生远离我。'

Oct 29, 2022

Create content rich websites with ease - built on next.js, contentlayer and tailwindcss

Create content rich websites with ease - built on next.js, contentlayer and tailwindcss

Pliny Note: Pliny is currently in alpha. Expect breaking changes. Pliny makes creating, editing and publishing markdown content easy and simple. It is

Dec 30, 2022

🎹 Memorize piano scales with ease! A music practice program w/ MIDI support. Consider it an interactive reference manual

🎹 Memorize piano scales with ease! A music practice program w/ MIDI support. Consider it an interactive reference manual

Piano Trainer Learn to play the piano at your own pace through various modes of practice. Watch the video Features MIDI compatible Home row keyboard i

Dec 21, 2022

Parse Ethers.js errors with ease 💅🏻

ethers-error-parser Parse Ethers.js errors with ease 💅🏻 Highlights Zero dependencies 🧹 Lightweight (637 bytes gzipped) 📦 Simple to use ⚡️ Work in

Dec 28, 2022

A CLI tool to generate barrels with ease, efficiency, and intelligence

A CLI tool to generate barrels with ease, efficiency, and intelligence

JS-Barrels A CLI tool to generate barrels with ease, efficiency, and intelligence Usage npx js-barrels -d ./folder/to/generate/barrels/for Options -d,

Aug 17, 2022

A JavaScript Library for building custom text editors with ease 📝

A JavaScript Library for building custom text editors with ease 📝

A JavaScript Library for building custom text editors with ease Show your support! Scriptor.js This is a bare bone text editor library, meant to creat

Oct 12, 2022
Comments
  • fast-check tips to detect race conditions

    fast-check tips to detect race conditions

    👋 Hello,

    I just opened the issue in case it can be helpful for the project.

    fast-check comes with a built-in arbitrary to ease detection of race conditions. You might be interested into relying on it in your tests too. See:

    • https://github.com/dubzzz/fast-check/blob/main/documentation/Tips.md#detect-race-conditions
    • https://codesandbox.io/s/github/dubzzz/fast-check/tree/main/example?hidenavigation=1&module=/005-race/autocomplete/main.spec.tsx&previewwindow=tests&file=/005-race/counter/main.spec.ts

    Please feel free to close the issue. It was mostly to let you know about the feature.

    opened by dubzzz 1
Owner
Tomer Aberbach
Working on @google Docs, Sheets, Slides et al. TCNJ grad enthused by web development, programming languages, compilers, functional programming, and type theory
Tomer Aberbach
Debounce promise-returning & async functions.

perfect-debounce An improved debounce function with Promise support. Well tested debounce implementation Native Promise support Avoid duplicate calls

unjs 55 Jan 2, 2023
Well-tested utility functions dealing with async iterables

aitertools This library provides a well-tested collection of small utility functions dealing with async iterables. You can think of it as LINQ or aite

Hong Minhee (洪 民憙) 11 Aug 15, 2022
Read Medium content without limit!

Medium Unlocker Read Medium content without limit! Aka replacer for Medium Unlimited. Get more information Please visit Wiki page Features Unlock grap

und3fined 303 Dec 24, 2022
Ajax library with XHR2, promises and request limit

qwest 4.5.0 ⚠ I finally decided to archive this repository. ⚠ At first, I developed Qwest because at the time other libraries were lacking of a proper

Aurélien Delogu 718 Sep 14, 2022
A rate-limiter using Durable Objects on CF Workers that actually doesn't rate limit anything.

Rate Limiter - built for Cloudflare Workers, using Durable Objects Features Supports fixed or sliding window algorithms Scoped rate-limiting Caching C

Ian 11 Dec 15, 2022
Unlocks all brainly answers and bypasses one answer per day limit. Gives infinite free answers & unlocks all textbooks 🔐 ∞

Brainly-LockPick ?? Unlocks all brainly answers and bypasses one answer per day limit. Gives infinite free answers & unlocks textbooks ?? ∞ Note: refr

null 7 Dec 9, 2022
Functions Recipes is a library of examples to help you getting started with Salesforce Functions and get used to their main features.

Functions Recipes Introduction Salesforce Functions lets you use the Salesforce Platform for building event-driven, elastically scalable apps and expe

Trailhead Apps 172 Dec 29, 2022
A tool to check for response status codes with ease

About Archer Archer is an cross-platform tool developed using Nodejs which focuses on the reconnaissance phase of a penetration test. Got a bunch of l

Umair 14 Oct 19, 2022
To Do List Application Organize your tasks with simple add and delete functionality. Organize your items with ease.

TODO-LIST To Do List Application Organize your tasks with simple add and delete functionality. Organize your items with ease. Additional description a

Steve 12 Jul 22, 2022
pokedev.js is a tool make to help developers get info about a pokemon and use it in any project with ease.

pokedev.js pokedev.js is a tool make to help developers get info about a pokemon and use it in any project with ease. Quick Links pokedev.js Quick Lin

pokedev.js 4 Apr 4, 2022