Table of Contents

Struct Deadline

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

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

Deadline

Zero

Already expired — immediate failure. Equivalent to default(Deadline).

public static readonly Deadline Zero

Field Value

Deadline

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

bool

IsInfinite

True if this deadline never expires (_ticks == long.MaxValue).

public bool IsInfinite { get; }

Property Value

bool

Remaining

Time remaining until this deadline expires. Returns Zero if already expired. Returns InfiniteTimeSpan if infinite.

public TimeSpan Remaining { get; }

Property Value

TimeSpan

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

int

Methods

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

Equals(Deadline)

Value equality: true if both deadlines carry the same absolute monotonic tick value.

public bool Equals(Deadline other)

Parameters

other Deadline

The deadline to compare against.

Returns

bool

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

timeout TimeSpan

Relative duration. Use InfiniteTimeSpan for no timeout. Zero or negative values produce an already-expired deadline.

Returns

Deadline

An absolute Deadline based on monotonic time.

GetHashCode()

public override int GetHashCode()

Returns

int

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

a Deadline
b Deadline

Returns

Deadline

ToCancellationToken()

Bridge a deadline to a .NET CancellationToken. Creates a CancellationTokenSource that cancels when the deadline expires.

public CancellationToken ToCancellationToken()

Returns

CancellationToken

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

string

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

left Deadline

Left operand.

right Deadline

Right operand.

Returns

bool

operator !=(Deadline, Deadline)

Value inequality: true if the deadlines carry different absolute monotonic tick values.

public static bool operator !=(Deadline left, Deadline right)

Parameters

left Deadline

Left operand.

right Deadline

Right operand.

Returns

bool