Timeout
Distinguishes finite relative waiting from explicitly endless waiting.
Module std.time
import std.time;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
Timeout
pub enum TimeoutDistinguishes finite relative waiting from explicitly endless waiting.
Integer and finite IEEE counts retain their exact magnitude or significand, binary exponent, sign and rational source unit until native tick normalization. No enormous sentinel substitutes for Endless: adapters receive none and must omit expiry registration. Cancellation, normal completion, closure and errors remain active for endless waits. Finite overflow never becomes endless. Default construction is zero finite wait. The value allocates nothing and retains no external borrow or clock owner.
Example
module example.timeout;
from std.time import Timeout, Milliseconds, BillionYears, DurationPeriod;
fn Main() -> i32 {
let NativeTick = switch DurationPeriod.TryCreate(1, 1000) {
case .Ok { Value = Value } => break Value;
case .Err { Error = _ } => return 1;
};
let Finite = switch Timeout.TryFromDuration(Milliseconds.Create(2250)) {
case .Ok { Value = Value } => break Value;
case .Err { Error = _ } => return 2;
};
switch Finite.TryTicks(NativeTick) {
case .Ok { Value = Ticks } => { if Ticks.Unwrap() != 2250 { return 3; } }
case .Err { Error = _ } => return 4;
}
let Zero = default(Timeout);
switch Zero.TryTicks(NativeTick) {
case .Ok { Value = Ticks } => { if Ticks.Unwrap() != 0 { return 11; } }
case .Err { Error = _ } => return 12;
}
let Endless: Timeout = .Endless;
switch Endless.TryTicks(NativeTick) {
case .Ok { Value = Ticks } => { if Ticks is .Some { Value = _ } { return 5; } }
case .Err { Error = _ } => return 6;
}
if Timeout.TryFromDuration(Milliseconds.Create(-1)) is .Ok { Value = _ } { return 7; }
let Long = switch Timeout.TryFromDuration(BillionYears.Create(1)) {
case .Ok { Value = Value } => break Value;
case .Err { Error = _ } => return 8;
};
switch Long {
case .Finite { Count = Count, Period = Period } => {
if Count.Magnitude != 1 || Period.Numerator != 31556952000000000 { return 9; }
}
case .Endless => return 10;
}
return 0;
}Timeout.Finite
Finite;Stores a finite count and source unit for checked native normalization.
Timeout.Finite.Count
Count: DurationMagnitude;Exact integer or finite IEEE count facts; adapters reject negative nonzero values.
Timeout.Finite.Period
Period: DurationPeriod;Positive reduced seconds unit, retained without nanosecond narrowing.
Timeout.Endless
Endless;Omits expiry registration while preserving cancellation and ordinary completion.
Timeout.TryFromDuration
pub static fn TryFromDuration<Rep, const Numerator: u64, const Denominator: u64>(
Value: readonly Duration<Rep, Numerator, Denominator>&) -> Result<Timeout, DurationError>
where Rep: Data, DurationCountValidates a relative finite duration without narrowing its unit or count. Rep: Copyable Defaultable integer or IEEE count representation. Numerator: Positive source unit seconds numerator. Denominator: Positive source unit seconds denominator. Value: Duration borrowed only for this validation/construction call. Return: Finite exact count/unit carrier or NegativeWait; no timer registration occurs.
Timeout.TryTicks
pub readonly fn TryTicks(TickPeriod: readonly DurationPeriod&) -> Result<u128?, DurationError>Normalizes finite native ticks upward, or reports explicit endless absence.
Positive fractional native ticks round up so a wait is not shortened. Native adapters must separately enforce their finite tick-width/range and perform the cancellation check before treating zero as immediately complete. Public payload construction does not bypass negative-count validation. TickPeriod: Positive reduced native tick unit borrowed for this call. Return: Some finite ticks, None for Endless, or checked negative/range error.