UNPKG

rsxjs

Version:

Resilience Extensions for JS.

22 lines (21 loc) 856 B
/** * @file src/coroutine/co.ts * @description Tiny coroutine runtime to provide features like canceling & * deferrals. * @copyright 2018-present Karim Alibhai. All rights reserved. */ import { DeferFunction } from '../deferral/types'; export interface Cancelable<T> extends Promise<T> { /** * Cancels the underlying operation. * @returns {boolean} true if the operation fully completed before first cancel was called */ cancel(): Promise<boolean>; } declare type Wrappable<T> = (...args: any[]) => Cancelable<T>; declare function wrap<T, F extends Wrappable<T> = Wrappable<T>, G = any>(fn: (defer: DeferFunction, ...args: any[]) => Iterator<any>): F; declare function runRoutine<T>(fn: (defer: DeferFunction) => Iterator<any>): Cancelable<T>; export declare const co: { wrap: typeof wrap; } & typeof runRoutine; export {};