Deadline
Distinguishes a finite monotonic deadline 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.
Deadline
pub enum DeadlineDistinguishes a finite monotonic deadline from explicitly endless waiting.
Values allocate nothing and retain no borrowed clock owner. Finite values require a valid Instant; their operations reject incompatible domains. Endless omits expiry while cancellation/normal completion remain active in adapters. No operation below samples a clock implicitly or registers a timer.
Example
module example.monotonic_deadline;
from std.time import Instant, Deadline, Timeout, Seconds;
fn Main() -> i32 {
let Start = switch Instant.TryNow() {
case .Ok { Value = Value } => break Value;
case .Err { Error = _ } => return 1;
};
// The trapping sampler has the same owned-domain contract. Comparing
// one sample with itself needs no assumption about sampling latency.
let Direct = Instant.Now();
if !Direct.IsValid { return 16; }
switch Direct.TryDifference(Direct) {
case .Ok { Value = Delta } => { if Delta.Count != 0_i128 { return 17; } }
case .Err => return 18;
}
let Later = Start + Seconds.Create(2);
let Limit: Deadline = .Finite { At = Later };
switch Limit.TryHasExpired(Start) {
case .Ok { Value = Expired } => { if Expired { return 2; } }
case .Err { Error = _ } => return 3;
}
switch Limit.TryHasExpired(Later) {
case .Ok { Value = Expired } => { if !Expired { return 4; } }
case .Err { Error = _ } => return 5;
}
if (Later - Start).Count != 2000000000_i128 { return 6; }
let Forever: Deadline = .Endless;
switch Forever.TryRemaining(Start) {
case .Ok { Value = Wait } => { if !(Wait is .Endless) { return 7; } }
case .Err { Error = _ } => return 8;
}
// Both overloads derive a boundary from the explicit start, so no second
// clock sample or scheduler timing assumption enters these comparisons.
let TypedLimit = switch Deadline.TryAfter(Start, Seconds.Create(2)) {
case .Ok { Value = Value } => break Value;
case .Err { Error = _ } => return 9;
};
let Relative = switch Timeout.TryFromDuration(Seconds.Create(2)) {
case .Ok { Value = Value } => break Value;
case .Err { Error = _ } => return 10;
};
let TimeoutLimit = switch Deadline.TryAfter(Start, Relative) {
case .Ok { Value = Value } => break Value;
case .Err { Error = _ } => return 11;
};
switch TypedLimit.TryHasExpired(Later) {
case .Ok { Value = Expired } => { if !Expired { return 12; } }
case .Err { Error = _ } => return 13;
}
switch TimeoutLimit.TryHasExpired(Start) {
case .Ok { Value = Expired } => { if Expired { return 14; } }
case .Err { Error = _ } => return 15;
}
return 0;
}Deadline.Finite
Finite;Stores a finite monotonic boundary; validity checked at use.
Deadline.Finite.At
At: Instant;Owned deadline instant; compatible-domain checks remain mandatory.
Deadline.Endless
Endless;Omits time expiry without suppressing cancellation or completion.
Deadline.TryAfter
pub static fn TryAfter(Start: readonly Instant&, Wait: readonly Timeout&) -> Result<Deadline, TimeError>Computes a deadline from an explicit start and validated relative wait. Start: Borrowed monotonic start; finite waits require a valid domain. Wait: Borrowed finite/endless timeout. Fractional nanoseconds round upward. Return: Finite derived boundary, Endless, or checked wait/domain/range failure.
Deadline.TryAfter
pub static fn TryAfter<Rep, const Numerator: u64, const Denominator: u64>(Start: readonly Instant&, Wait: readonly Duration<Rep, Numerator, Denominator>&) -> Result<Deadline, TimeError> where Rep: Data, DurationCountComputes a finite deadline directly from a typed relative duration. Rep: Copyable Defaultable numeric count. Numerator: Positive seconds numerator. Denominator: Positive seconds denominator. Start: Borrowed valid monotonic start. Wait: Borrowed relative duration; negative nonzero waits are rejected. Return: Derived finite boundary or checked duration/domain/range failure.
Deadline.TryHasExpired
pub readonly fn TryHasExpired(Now: readonly Instant&) -> Result<bool, TimeError>Tests expiry against explicitly supplied monotonic time. Now: Borrowed sampled/derived instant; finite comparison requires a compatible domain. Return: True at/past finite expiry, false for future/endless, or domain error.
Deadline.TryRemaining
pub readonly fn TryRemaining(Now: readonly Instant&) -> Result<Timeout, TimeError>Computes remaining relative wait without sampling or registering a timer. Now: Borrowed time in the finite deadline domain. Return: Exact positive wait, zero when elapsed, Endless when explicit, or domain/range error.