menu

TaskScope

import { TaskScope } from "destack:async";

Structured owner of spawned tasks.

Asynchronous disposal waits for every child before it completes. Cancellation requests are delivered cooperatively at cancellable asynchronous operations.

language/library/src/async/task.ds:105:133
1export struct TaskScope {2    static open(): TaskScope;3    spawn<T: Copy>(body: () => Task<T>): Task<T>;4    cancel(): void;5    async asyncDispose(): Promise<void>;6    drop(): void;7}

Members

static open(): TaskScope

Open a new task scope.

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

Spawn one task owned by this scope.

cancel(): void

Request cancellation of every pending child.

async asyncDispose(): Promise<void>

Cancel pending children and wait for their cleanup.

drop(): void

Cancel pending children and detach their cleanup.