UNPKG

@rushstack/operation-graph

Version:

Library for managing and executing operations in a directed acyclic graph.

87 lines 2.79 kB
import type { OperationRequestRunCallback } from './Operation'; import { OperationStatus } from './OperationStatus'; import type { IPCHost } from './protocol.types'; /** * Callbacks for the watch loop. * * @beta */ export interface IWatchLoopOptions { /** * Callback that performs the core work of a single iteration. */ executeAsync: (state: IWatchLoopState) => Promise<OperationStatus>; /** * Logging callback immediately before execution occurs. */ onBeforeExecute: () => void; /** * Logging callback when a run is requested (and hasn't already been). * * @param requestor - The name of the operation requesting a rerun. * @param detail - Optional detail about why the rerun is requested, e.g. the name of a changed file. */ onRequestRun: OperationRequestRunCallback; /** * Logging callback when a run is aborted. */ onAbort: () => void; } /** * The public API surface of the watch loop, for use in the `executeAsync` callback. * * @beta */ export interface IWatchLoopState { get abortSignal(): AbortSignal; requestRun: OperationRequestRunCallback; } /** * This class implements a watch loop. * * @beta */ export declare class WatchLoop implements IWatchLoopState { private readonly _options; private _abortController; private _isRunning; private _runRequested; private _requestRunPromise; private _resolveRequestRun; constructor(options: IWatchLoopOptions); /** * Runs the inner loop until the abort signal is cancelled or a run completes without a new run being requested. */ runUntilStableAsync(abortSignal: AbortSignal): Promise<OperationStatus>; /** * Runs the inner loop until the abort signal is aborted. Will otherwise wait indefinitely for a new run to be requested. */ runUntilAbortedAsync(abortSignal: AbortSignal, onWaiting: () => void): Promise<void>; /** * Sets up an IPC handler that will run the inner loop when it receives a "run" message from the host. * Runs until receiving an "exit" message from the host, or aborts early if an unhandled error is thrown. */ runIPCAsync(host?: IPCHost): Promise<void>; /** * Requests that a new run occur. */ requestRun: OperationRequestRunCallback; /** * The abort signal for the current iteration. */ get abortSignal(): AbortSignal; /** * Cancels the current iteration (if possible). */ private _abortCurrent; /** * Resets the abort signal and run request state. */ private _reset; /** * Runs a single iteration of the loop. * @returns The status of the iteration. */ private _runIterationAsync; } //# sourceMappingURL=WatchLoop.d.ts.map