Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

Task

Owns one single-consumer asynchronous operation without copying its frame.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. Read the status →

Module std.task

import std.task;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

Task

pub final class Task<T>

Owns one single-consumer asynchronous operation without copying its frame. T: Owned completion value; void represents no-value completion. @details Empty and moved-from handles own no frame. Dropping the last visible owner requests cancellation without blocking; runtime/native pins retain work through terminal cleanup. Await consumes a completion once without resetting the handle. Reference completion specializations are outside this package.

Example

module example.task_ownership;
from std.task import Task, SharedTask, Share;
async fn AnswerAsync() -> Task<i32> { return 42; }
async fn Main() -> Task<i32> {
    var Empty = Task<i32>();
    var Moved = move(Empty);
    Empty = move(Moved);
    if Empty.IsCompleted || Moved.IsCompleted { return 1; }
    var EmptyShared = SharedTask<i32>();
    var EmptyCopy = EmptyShared;
    EmptyCopy = EmptyShared;
    var EmptyMoved = move(EmptyCopy);
    EmptyCopy = move(EmptyMoved);
    if EmptyCopy.IsCompleted || EmptyMoved.IsCompleted { return 2; }
    var Pending = AnswerAsync();
    let Shared = Share(move(Pending));
    let Copy = Shared;
    let First = await Shared;
    let Again = await Copy;
    if First != 42 || Again != 42 || !Shared.IsCompleted { return 3; }
    return 0;
}

Task.init

pub init()

Initializes an empty handle without allocating.

Task.init

pub init(Source: readonly Self&) = delete;

Rejects duplicating a unique result consumer. Source: Existing unique handle; copying is forbidden even when empty.

Task.init

pub init(Source: mut Self&&)

Moves the existing owner and leaves Source empty. Source: Explicitly moved live owner.

Task.operator

pub fn operator =(Source: readonly Self&) -> void = delete;

Rejects copy assignment of a unique result consumer. Source: Existing handle whose single-consumer ownership cannot be copied. Return: No runtime result; copy assignment is rejected at compile time.

Task.operator

pub fn operator =(Source: mut Self&&) -> void

Releases the old owner and moves Source, with harmless exact self-assignment. Source: Explicitly moved owner. Return: No value.

Task.IsCompleted

pub IsCompleted: bool;

Observes completed result publication without consuming it. Return: False for empty/pending handles; true after terminal publication.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library