All Projects → ForbesLindesay → Throat

ForbesLindesay / Throat

Licence: mit
Throttle a collection of promise returning functions

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
flow
126 projects

Projects that are alternatives of or similar to Throat

Tascalate Concurrent
Implementation of blocking (IO-Bound) cancellable java.util.concurrent.CompletionStage and related extensions to java.util.concurrent.ExecutorService-s
Stars: ✭ 144 (-65.63%)
Mutual labels:  promise, concurrency
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (-53.94%)
Mutual labels:  promise, concurrency
P Map
Map over promises concurrently
Stars: ✭ 639 (+52.51%)
Mutual labels:  promise, concurrency
Start
🔴 Functional task runner for Node.js
Stars: ✭ 478 (+14.08%)
Mutual labels:  promise, concurrency
Post Me
📩 Use web Workers and other Windows through a simple Promise API
Stars: ✭ 398 (-5.01%)
Mutual labels:  promise, concurrency
async
Synchronization and asynchronous computation package for Go
Stars: ✭ 104 (-75.18%)
Mutual labels:  promise, concurrency
p-ratelimit
Promise-based utility to make sure you don’t call rate-limited APIs too quickly.
Stars: ✭ 49 (-88.31%)
Mutual labels:  promise, concurrency
wise-river
Object streaming the way it should be.
Stars: ✭ 33 (-92.12%)
Mutual labels:  promise, concurrency
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-95.23%)
Mutual labels:  promise, concurrency
conquerant
lightweight async/await for Clojure
Stars: ✭ 31 (-92.6%)
Mutual labels:  promise, concurrency
easy-promise-queue
An easy JavaScript Promise queue which is automatically executed, concurrency controlled and suspendable.
Stars: ✭ 31 (-92.6%)
Mutual labels:  promise, concurrency
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+801.91%)
Mutual labels:  promise, concurrency
Cloudi
A Cloud at the lowest level!
Stars: ✭ 352 (-15.99%)
Mutual labels:  concurrency
Ava
Node.js test runner that lets you develop with confidence 🚀
Stars: ✭ 19,458 (+4543.91%)
Mutual labels:  concurrency
Jruby
JRuby is an implementation of the Ruby language using the JVM.
Stars: ✭ 3,576 (+753.46%)
Mutual labels:  concurrency
Ws
⚠️ Deprecated - (in favour of Networking) ☁️ Elegantly connect to a JSON api. (Alamofire + Promises + JSON Parsing)
Stars: ✭ 352 (-15.99%)
Mutual labels:  promise
Octokat.js
Github API Client using Promises or callbacks. Intended for the browser or NodeJS.
Stars: ✭ 401 (-4.3%)
Mutual labels:  promise
Pagarme Js
💛 Pagar.me's JavaScript API
Stars: ✭ 370 (-11.69%)
Mutual labels:  promise
Magicmusic
🎵帅气的手机端音乐播放器(vue vue-router vuex flex ...)
Stars: ✭ 350 (-16.47%)
Mutual labels:  promise
Concurrencpp
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all
Stars: ✭ 340 (-18.85%)
Mutual labels:  concurrency

throat

Throttle the parallelism of an asynchronous, promise returning, function / functions. This has special utility when you set the concurrency to 1. That way you get a mutually exclusive lock.

Professionally supported throat is now available

Build Status Coveralls github branch Rolling Versions NPM version

Installation

npm install throat

API

throat(concurrency)

This returns a function that acts a bit like a lock (exactly as a lock if concurrency is 1).

Example, only 2 of the following functions will execute at any one time:

const throat = require('throat')(2);

const resA = throat(async () => { /* async stuff... */ });
const resB = throat(async () => { /* async stuff... */ });
const resC = throat(async () => { /* async stuff... */ });
const resD = throat(async () => { /* async stuff... */ });
const resE = throat(async () => { /* async stuff... */ });

throat(concurrency, worker)

This returns a function that is an exact copy of worker except that it will only execute up to concurrency times in parallel before further requests are queued:

const throat = require('throat');

const input = ['fileA.txt', 'fileB.txt', 'fileC.txt', 'fileD.txt'];
const data = Promise.all(
  input.map(throat(2, (fileName) => readFile(fileName)))
);

Only 2 files will be read at a time, sometimes limiting parallelism in this way can improve scalability.

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].