Skip to content

Namespace Concurrent

Package: @litert/concurrentImport path: @litert/concurrentSource: packages/partials/concurrent/src/

The Concurrent namespace provides utilities for managing concurrent operations, including throttling, debouncing, rate limiting, circuit breaking, mutexes, and fiber pools.

Install

Use this namespace only:

bash
npm i @litert/concurrent

Or install the full bundle:

bash
npm i @litert/utils

And then import from it.

ts
import * as LibUtils from '@litert/utils';
const mutex = new LibUtils.Concurrent.MemoryMutex();

// or
import { Concurrent as LibConcurrent } from '@litert/utils';
const mutex = new LibConcurrent.MemoryMutex();

Errors

SymbolDescription
E_RATE_LIMITEDThrown when a rate limiter blocks a call
E_BREAKER_OPENEDThrown when a circuit/manual breaker is open
E_LOCK_FAILEDThrown when a mutex lock cannot be acquired

Typings

See Typings.md for shared interfaces used across multiple APIs.

NameDescription
ICounterGeneric counter interface used by CountingRateLimiter and CircuitBreaker.
ISimpleFnType for a zero-parameter function.
IBreakerInterface implemented by all circuit breaker classes.
ISyncRateLimiterInterface for synchronous rate limiters.
ISyncRateLimiterManagerInterface for managing per-key synchronous rate limiters.
IAsyncRateLimiterInterface for asynchronous rate limiters.
IAsyncRateLimiterManagerInterface for managing per-key asynchronous rate limiters.

Class-specific option and event interfaces are documented on each class's page.


Classes

Flow Control

ClassDescription
ThrottleController<T>Throttles concurrent async function calls — deduplicates in-flight calls by ID
DebounceControllerDebounces a function call with optional max-delay cap
BatchBuffer<T>Buffers items and delivers them in batches on timer or capacity

Counters & Rate Limiters

ClassDescription
SlideWindowCounterSliding time-window counter divided into sub-windows
CountingRateLimiterSync rate limiter backed by any ICounter
TokenBucketRateLimiterSync rate limiter using the token-bucket algorithm
LeakyBucketRateLimiterAsync rate limiter using the leaky-bucket algorithm
TokenBucketRateLimiterManagerPer-key token-bucket manager
LeakyBucketRateLimiterManagerPer-key leaky-bucket manager

Synchronization

ClassDescription
MemoryMutexIn-memory mutex with optional reentrant support
FiberPoolPool of FiberController workers for concurrent task execution

Circuit Breakers

ClassDescription
ManualBreakerManually controlled circuit breaker
CircuitBreakerAutomatic circuit breaker with half-open recovery