UNPKG

@effectful/cc

Version:

Multi-prompt delimited continuations runtime

43 lines (42 loc) 1.77 kB
export type CancellationCallback = () => void; export type CancellationCallbacks = Set<CancellationCallback>; export type Transaction = { /** * Runs `body` in this transaction scope. * Anything calling `addOnRollback` inside the body will register into it. */ run<T>(body: () => T): T; }; export declare function currentCancellationCallbacks(): CancellationCallbacks | undefined; /** * Begins a nested cancellation "transaction". * * - Creates a fresh cancellation scope (`Set`). * - Registers a drain callback into the parent scope (if any), so parent * cancellation cancels this transaction too. */ export declare function begin(name?: string): Transaction; /** * Commits a transaction. * * This doesn't drain and doesn't detach from the parent, so rolling back the * parent later will still roll back this committed transaction too. * * In zone terms, "moving focus to parent" is done by simply leaving `tx.run`. */ export declare function commit(tx?: Transaction): void; /** * Rolls back a transaction. * * - Drains the transaction scope. * - Detaches the transaction from the parent scope. */ export declare function rollback(tx?: Transaction): void; export declare function addOnRollback(callback: CancellationCallback): void; export declare function removeOnRollback(callback: CancellationCallback): void; export declare const addOnCancel: typeof addOnRollback; export declare const removeOnCancel: typeof removeOnRollback; export declare const deleteOnCancel: typeof removeOnRollback; export declare function cancel(target?: unknown): void; export declare function withCancellationCallbacks<T>(callbacks: CancellationCallbacks, body: () => T): T; export declare function installCancelablePromise(PromiseImpl?: any): any;