UNPKG

decurse

Version:

An abstraction over continuation-passing and trampolining to write recursive functions that don't exceed the maximum call stack size.

19 lines (18 loc) 607 B
import type { LaxPartial } from "@samual/types"; export type Decurse = { pending: (() => void)[]; active: boolean; autoPump: boolean; <T>(callback: () => T | OffStack<T>): OffStack<T>; }; export type DecurseOptions = LaxPartial<{ autoPump: boolean; }>; export declare class OffStack<T> { #private; private constructor(); then<U>(callback: (result: T) => U | OffStack<U>): OffStack<U>; } export declare function pump(decurse: Decurse): void; export declare function pumpAll(decurse: Decurse): void; export declare function makeDecurse({ autoPump }?: DecurseOptions): Decurse;