Struct Deadline
A monotonic absolute deadline for timeout enforcement. Convert a relative TimeSpan to Deadline once at the operation entry point, then share the deadline through all nested calls — eliminating timeout accumulation.
public readonly struct Deadline : IEquatable<Deadline>
- Implements
- Inherited Members
Remarks
default(Deadline) is already expired (fail-safe). Use Infinite for unbounded waits.
All time conversions use pure integer arithmetic via the precomputed Typhon.Engine.Deadline.TickRatio constant. No floating-point operations exist anywhere in this type.
Fields
Infinite
No timeout — never expires.
public static readonly Deadline Infinite
Field Value
Zero
Already expired — immediate failure. Equivalent to default(Deadline).
public static readonly Deadline Zero
Field Value
Properties
IsExpired
True if the deadline has passed.
Always false for Infinite. Always true for Zero/default.
Each call reads GetTimestamp() — not cached.
public bool IsExpired { get; }
Property Value
IsInfinite
True if this deadline never expires (_ticks == long.MaxValue).
public bool IsInfinite { get; }
Property Value
Remaining
Time remaining until this deadline expires. Returns Zero if already expired. Returns InfiniteTimeSpan if infinite.
public TimeSpan Remaining { get; }
Property Value
RemainingMilliseconds
Remaining time in milliseconds. Returns 0 if expired, -1 if infinite. Suitable for .NET wait APIs (Wait(object, int), WaitOne(int)).
public int RemainingMilliseconds { get; }
Property Value
Methods
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
Equals(Deadline)
Value equality: true if both deadlines carry the same absolute monotonic tick value.
public bool Equals(Deadline other)
Parameters
otherDeadlineThe deadline to compare against.
Returns
FromTimeout(TimeSpan)
Convert a relative timeout to an absolute monotonic deadline. Call this once at the operation entry point, then share the deadline through all nested calls.
public static Deadline FromTimeout(TimeSpan timeout)
Parameters
timeoutTimeSpanRelative duration. Use InfiniteTimeSpan for no timeout. Zero or negative values produce an already-expired deadline.
Returns
GetHashCode()
public override int GetHashCode()
Returns
Min(Deadline, Deadline)
Returns the tighter (earlier) of two deadlines. Useful when an inner operation has its own timeout that must also respect the outer deadline.
public static Deadline Min(Deadline a, Deadline b)
Parameters
Returns
ToCancellationToken()
Bridge a deadline to a .NET CancellationToken. Creates a CancellationTokenSource that cancels when the deadline expires.
public CancellationToken ToCancellationToken()
Returns
Remarks
WARNING: This allocates a CancellationTokenSource with a timer. Use sparingly — only when interacting with .NET APIs that require a CancellationToken (e.g., HttpClient, Stream.ReadAsync). For Typhon's own lock primitives, use WaitContext directly.
ToString()
public override string ToString()
Returns
Operators
operator ==(Deadline, Deadline)
Value equality: true if both deadlines carry the same absolute monotonic tick value.
public static bool operator ==(Deadline left, Deadline right)
Parameters
Returns
operator !=(Deadline, Deadline)
Value inequality: true if the deadlines carry different absolute monotonic tick values.
public static bool operator !=(Deadline left, Deadline right)