UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

35 lines • 1.8 kB
/** * Limit concurrent async operations within one process. * * Twin of python's `concurrency/limiter.py`, which wraps * `asyncio.Semaphore`. Node has no built-in semaphore, so the queue is * explicit -- but the two contracts match: a permit count below one is * rejected rather than clamped, and a release hands its permit straight * to the longest-waiting caller instead of returning it to the pool. * Handing off matters: returning it first would let a caller arriving in * the same tick barge ahead of the queue and drive the count negative. */ export declare class ConcurrencyLimiter { private available; private readonly waiters; constructor(maxConcurrency: number); /** * Take one permit, waiting for a free one, and return its release. * * The release is idempotent so a caller that unwinds twice (a `finally` * plus an explicit call) cannot inflate the permit count -- python gets * that from `async with` and the shape here has to supply it. An abort * leaves the queue without a permit, as a cancelled `acquire` does in * python. * * Args: * signal: abandons the wait when it fires. */ acquire(signal?: AbortSignal): Promise<() => void>; private release; } /** Map in order with bounded workers; a failure stops admission and joins active work. */ export declare function boundedMap<T, R>(items: readonly T[], fn: (item: T) => Promise<R>, workers: number): Promise<R[]>; /** Map a stream in input order, owning all admitted work through cancellation. */ export declare function boundedMapStream<T, R>(items: (signal: AbortSignal) => AsyncIterable<T>, fn: (item: T, signal: AbortSignal) => Promise<R>, workers: number, parent?: AbortSignal): AsyncGenerator<R>; //# sourceMappingURL=limiter.d.ts.map