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/concurrentOr install the full bundle:
bash
npm i @litert/utilsAnd 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
| Symbol | Description |
|---|---|
E_RATE_LIMITED | Thrown when a rate limiter blocks a call |
E_BREAKER_OPENED | Thrown when a circuit/manual breaker is open |
E_LOCK_FAILED | Thrown when a mutex lock cannot be acquired |
Typings
See Typings.md for all exported interfaces and types, including:
ICounterISimpleFnIBreakerISyncRateLimiterISyncRateLimiterManagerIAsyncRateLimiterIAsyncRateLimiterManager- Option interfaces for all classes
Classes
Flow Control
| Class | Description |
|---|---|
ThrottleController<T> | Throttles concurrent async function calls — deduplicates in-flight calls by ID |
DebounceController | Debounces a function call with optional max-delay cap |
BatchBuffer<T> | Buffers items and delivers them in batches on timer or capacity |
Counters & Rate Limiters
| Class | Description |
|---|---|
SlideWindowCounter | Sliding time-window counter divided into sub-windows |
CountingRateLimiter | Sync rate limiter backed by any ICounter |
TokenBucketRateLimiter | Sync rate limiter using the token-bucket algorithm |
LeakyBucketRateLimiter | Async rate limiter using the leaky-bucket algorithm |
TokenBucketRateLimiterManager | Per-key token-bucket manager |
LeakyBucketRateLimiterManager | Per-key leaky-bucket manager |
Synchronization
| Class | Description |
|---|---|
MemoryMutex | In-memory mutex with optional reentrant support |
FiberPool | Pool of FiberController workers for concurrent task execution |
Circuit Breakers
| Class | Description |
|---|---|
ManualBreaker | Manually controlled circuit breaker |
CircuitBreaker | Automatic circuit breaker with half-open recovery |