Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

Yield

Cooperatively queues a continuation on the captured executor without blocking it.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. 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.

YieldAsync

pub async fn YieldAsync(Token: CancellationToken) -> Task<Result<void, YieldError>>

Cooperatively queues a continuation on the captured executor without blocking it. Token: Owned retained user cancellation observation, inert by default. Return: Unique task with success or typed cancellation/executor startup error. Makes no timing or strict fairness promise. Native facilities start lazily; a yield creates no timer or per-call OS thread. Await returns to the same captured route, including an explicit blocking executor. No source unsafe block is needed.

Example

module example.cooperative_yield;
from std.task import Task, YieldAsync, CancellationSource;
async fn Main() -> Task<i32> {
    switch await YieldAsync() { case .Ok => {} case .Err => return 1; }
    var Source = {
        // Keep writable result storage through the explicit noncopy payload transfer.
        var SourceCreation = CancellationSource.TryCreate();
        switch SourceCreation {
            case .Ok { Value = Value: mut CancellationSource& } => break move(Value);
            case .Err => return 2;
        }
    };
    if !Source.RequestCancellation() { return 3; }
    switch await YieldAsync(Source.Token) {
        case .Ok => return 4;
        case .Err { Error = Error } => { if !(Error is .Cancelled) { return 5; } }
    }
    return 0;
}

YieldAsync

pub fn YieldAsync() -> Task<Result<void, YieldError>>

Supplies the omitted arguments to YieldAsync. Note: Defaults: Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

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