menu

Task

import { Task } from "destack:async";

Single-consumer asynchronous result on its own fiber.

Awaiting a task blocks the current fiber and moves the result out. Cancellation requests are delivered cooperatively at cancellable operations.

language/library/src/async/task.ds:13:72
1export class Task<T> {2    static resolve<T>(value: T): Task<T>;3    static spawn<T>(body: () => T): Task<T>;4    static block<T>(task: Task<T>): T;5    cancel(): void;6}

Members

static resolve<T>(value: T): Task<T>

Create an already completed task.

static spawn<T>(body: () => T): Task<T>

Run one body on a fresh fiber and expose its result.

static block<T>(task: Task<T>): T

Block the current fiber until a task completes, moving the result out.

cancel(): void

Request cancellation at the next suspension.