/** * Gets a handle to the task that invoked it. Useful when task needs to * suspend execution until some outside event occurs, in which case handle * can be used resume execution (see `suspend` code example for more details) * * @template T, M, X * @returns {Task.Task, never>} */ export function current(): Task.Task, never, never>; /** * Suspends execution for the given duration in milliseconds, after which * execution is resumed (unless it was aborted in the meantime). * * @example * ```js * function * demo() { * console.log("I'm going to take small nap") * yield * sleep(200) * console.log("I am back to work") * } * ``` * * @param {number} [duration] * @returns {Task.Task} */ export function sleep(duration?: number | undefined): Task.Task; /** * Takes several effects and combines them into a one. * * @template T * @param {Task.Effect[]} effects * @returns {Task.Effect} */ export function batch(effects: Task.Effect[]): Task.Effect; /** * Kind of like promise.then which is handy when you want to extract result * from the given task from the outside. * * @template T, U, X, M * @param {Task.Task} task * @param {(value:T) => U} resolve * @param {(error:X) => U} reject * @returns {Task.Task} */ export function then(task: Task.Task, resolve: (value: T) => U, reject: (error: X) => U): Task.Task; /** * Executes given task concurrently with a current task (task that spawned it). * Spawned task is detached from the task that spawned it and it can outlive it * and / or fail without affecting a task that spawned it. If you need to wait * on concurrent task completion consider using `fork` instead which can be * later `joined`. If you just want a to block on task execution you can just * `yield* work()` directly instead. * * @param {Task.Task} task * @returns {Task.Task} */ export function spawn(task: Task.Task): Task.Task; /** * Groups multiple forks togather and joins joins them with current task. * * @template T, X, M * @param {Task.Fork[]} forks * @returns {Task.Task} */ export function group(forks: Task.Fork[]): Task.Task; /** * @template T, X, M * @param {Task.Fork} fork * @returns {Task.Task} */ export function join(fork: Task.Fork): Task.Task; export * from "./task.js"; export function effect(task: Task.Task): Task.Effect; export function suspend(): Task.Task; export function wait(input: Task.Await): Task.Task; export function send(message: T): Task.Effect; export function listen(source: { [K in Tag]: Task.Effect; }): Task.Effect>; export function effects(tasks: Task.Task[]): Task.Effect; export function tag(effect: Task.Task, tag: Tag): Task.Task>; /** * Returns empty `Effect`, that is produces no messages. Kind of like `[]` or * `""` but for effects. * * @type {() => Task.Effect} */ export const none: () => Task.Effect; export function all(tasks: Iterable>): Task.Task; export function isMessage(value: Task.Instruction): value is M; export function isInstruction(value: Task.Instruction): value is Task.Control; export function main(task: Task.Task): void; export function resume(task: Task.Controller): void; export function fork(task: Task.Task, options?: Task.ForkOptions | undefined): Task.Fork; export function exit(handle: Task.Controller, value: T): Task.Task; export function terminate(handle: Task.Controller): Task.Task & Task.Controller; export function abort(handle: Task.Controller, error?: X | undefined): Task.Task & Task.Controller; export function loop(init: Task.Effect, next: (message: M) => Task.Effect): Task.Task; export type Tagged = { type: Tag; } & { [K in Tag]: T; }; export type Control = typeof SUSPEND | typeof CURRENT; import * as Task from "./task.js"; /** * @template T, X, M * @implements {Task.Fork} * @implements {Task.Controller} * @implements {Task.Task, never>} * @implements {Task.Future} * @extends {Future} */ declare class Fork extends Future implements Task.Fork, Task.Controller, Task.Task, never>, Task.Future { /** * @param {Task.Task} task * @param {Task.ForkOptions} [options] * @param {Task.StateHandler} [handler] * @param {Task.TaskState} [state] */ constructor(task: Task.Task, options?: Task.ForkOptions | undefined, handler?: Task.StateHandler | undefined, state?: Task.TaskState | undefined); id: number; name: string; /** @type {Task.Task} */ task: Task.Task; state: Task.TaskState; status: Task.Status; /** @type {Task.Controller} */ controller: Task.Controller; resume(): Generator; /** * @returns {Task.Task} */ join(): Task.Task; /** * @param {X} error */ abort(error: X): Task.Task & Task.Controller; /** * @param {T} value */ exit(value: T): Task.Task; /** * @private * @param {any} error * @returns {never} */ private panic; /** * @private * @param {Task.TaskState} state */ private step; /** * @param {unknown} value */ next(value: unknown): Task.TaskState; /** * @param {T} value */ return(value: T): Task.TaskState; /** * @param {X} error */ throw(error: X): Task.TaskState; get [Symbol.toStringTag](): string; /** * @returns {Task.Controller, never, never>} */ [Symbol.iterator](): Task.Controller, never, never>; } declare const SUSPEND: unique symbol; declare const CURRENT: unique symbol; /** * @template T, X * @implements {Task.Future} */ declare class Future implements Task.Future { /** * @param {Task.StateHandler} handler */ constructor(handler: Task.StateHandler); handler: Task.StateHandler; /** * @abstract * @type {Task.Result|void} */ result: Task.Result | void; /** * @type {Promise} */ get promise(): Promise; /** * @template U, [E=never] * @param {((value:T) => U | PromiseLike)|undefined|null} [onresolve] * @param {((error:X) => E|PromiseLike)|undefined|null} [onreject] * @returns {Promise} */ then(onresolve?: ((value: T) => U | PromiseLike) | null | undefined, onreject?: ((error: X) => E | PromiseLike) | null | undefined): Promise; /** * @template [U=never] * @param {(error:X) => U} onreject */ catch(onreject: (error: X) => U_1): Task.Future; /** * @param {() => void} onfinally * @returns {Task.Future} */ finally(onfinally: () => void): Task.Future; /** * @abstract */ activate(): Future; } //# sourceMappingURL=lib.d.ts.map