# 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.

```ds title="Task"
export class Task<T> {
    static resolve<T>(value: T): Task<T>;
    static spawn<T>(body: () => T): Task<T>;
    static block<T>(task: Task<T>): T;
    cancel(): void;
}
```

[language/library/src/async/task.ds:13:72](https://github.com/destack-sh/destack/blob/main/language/library/src/async/task.ds#L13-L72)

## 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.
