Delay
Waits without blocking a worker, using checked relative monotonic time.
Module std.task
import std.task;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
DelayAsync
pub async fn DelayAsync(Wait: Timeout, mut Token: CancellationToken) -> Task<Result<void, DelayError>>Waits without blocking a worker, using checked relative monotonic time. Token: Retained user cancellation observation, inert by default. Wait: Owned finite timeout or explicit Endless. Default Timeout completes immediately. Return: Unique task containing success or typed validation/cancellation/scheduling error. Positive fractional ticks round upward. Negative waits fail before registration; finite overflow remains an error. Root lifetime cancellation remains cooperative. User Token is owned retained observation with an inert default. Native facilities start lazily only for pending waiting; cancellation does not fabricate success.
Example
module example.delay;
from std.task import Task, DelayAsync;
from std.time import Milliseconds;
async fn Main() -> Task<i32> {
switch await DelayAsync(Milliseconds.Create(0)) {
case .Ok => {}
case .Err { Error = _ } => return 1;
}
switch await DelayAsync(Milliseconds.Create(-1)) {
case .Ok => return 2;
case .Err { Error = _ } => {}
}
switch await DelayAsync(Milliseconds.Create(1)) {
case .Ok => return 0;
case .Err { Error = _ } => return 3;
}
}DelayAsync
pub fn DelayAsync(mut Wait: Timeout) -> Task<Result<void, DelayError>>Supplies the omitted arguments to DelayAsync. Note: Defaults: Token = CancellationToken(). Wait: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.
DelayAsync
pub async fn DelayAsync<Rep, const Numerator: u64, const Denominator: u64>(Wait: Duration<Rep, Numerator, Denominator>, mut Token: CancellationToken) -> Task<Result<void, DelayError>>
where Rep: Data, DurationCountValidates an owned duration and waits through the same monotonic timer path. Rep: Copyable Defaultable integer or IEEE count representation. Numerator: Positive seconds numerator. Denominator: Positive seconds denominator. Token: Retained user cancellation observation, inert by default. Wait: Owned duration, with no external reference retained across suspension. Return: Success or exact typed validation/cancellation/scheduling error.
DelayAsync
pub fn DelayAsync<Rep, const Numerator: u64, const Denominator: u64>(mut Wait: Duration<Rep, Numerator, Denominator>) -> Task<Result<void, DelayError>>
where Rep: Data, DurationCountSupplies the omitted arguments to DelayAsync. Note: Defaults: Token = CancellationToken(). Rep: Same generic argument and constraints as the full operation. Numerator: Same generic argument and constraints as the full operation. Denominator: Same generic argument and constraints as the full operation. Wait: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.