Skip to content

Executors

Executors accept task functions through a shared exec() API and apply a scheduling policy. They are useful when several call sites should share the same concurrency, ordering, or protection rules.

import { PoolTaskExecutor, RateLimitExecutor } from "@vgerbot/async";
import { PoolTaskExecutor } from "@vgerbot/async/executors";
interface ITaskExecutor {
cancel(reason?: unknown): void;
cancel(options: TaskCancelOptions): void;
cancel(reason: unknown, options: TaskCancelOptions): void;
isCancelled(): boolean;
shutdown(reason?: unknown): void;
exec<T>(task: AsyncTask<T>, options?: TaskOptions): TaskHandle<T>;
}
API Description
ITaskExecutor Common executor interface.
PoolTaskExecutor Runs submitted tasks with fixed concurrency.
SeriesTaskExecutor Runs submitted tasks one at a time in order.
PriorityPoolExecutor Runs queued tasks by priority with pool concurrency.
RateLimitExecutor Limits how many tasks can start within a time window.
CircuitBreakerExecutor Stops calls temporarily when failures exceed a threshold.
DebounceTaskExecutor Debounces task execution.
ThrottleTaskExecutor Throttles task execution.

TaskOptions lets callers label submitted work.

Option Description
kind Grouping key used by selective cancellation where supported.
name Human-readable task label for debugging and observability.
metadata Additional caller-provided task metadata.