Time
Namespace: E2E.Internal
public static class TimeDeadline and polling helpers, as upstream’s internal/time.ts.
Inheritance: object
Fields
Section titled “Fields”NegationGrace
Section titled “NegationGrace”public static readonly TimeSpan NegationGraceHow long a negated assertion must hold before it passes.
Value: TimeSpan
public static readonly DateTimeOffset NeverThe deadline of a step that has none of its own and no running phase to end it: far enough that nothing reaches it, and not MaxValue, so adding a read’s time to it cannot overflow.
Value: DateTimeOffset
PollInterval
Section titled “PollInterval”public static readonly TimeSpan PollIntervalCanonical polling cadence for locator and assertion loops.
Value: TimeSpan
Unbounded
Section titled “Unbounded”public static readonly TimeSpan UnboundedThe longest budget handed to an engine read or a timer: a day, standing for no limit when nothing caps a step.
Value: TimeSpan
Methods
Section titled “Methods”Between(TimeSpan, TimeSpan, TimeSpan)
Section titled “Between(TimeSpan, TimeSpan, TimeSpan)”public static TimeSpan Between(TimeSpan value, TimeSpan least, TimeSpan most)<code class=“paramref”>value</code> held between <code class=“paramref”>least</code> and <code class=“paramref”>most</code> (.NET-only helper for upstream’s Math.max(1, ms)).
Parameters
| Name | Type | Description |
|---|---|---|
value |
TimeSpan | |
least |
TimeSpan | |
most |
TimeSpan |
Returns: TimeSpan
BudgetText(long)
Section titled “BudgetText(long)”public static string BudgetText(long ms)A budget as a message names it, exactly, in the largest unit that divides it: 5m, 30s, 1500ms (upstream’s budgetText).
Parameters
| Name | Type | Description |
|---|---|---|
ms |
long |
Returns: string
CheckStepTimeout(TimeSpan?, string)
Section titled “CheckStepTimeout(TimeSpan?, string)”public static void CheckStepTimeout(TimeSpan? timeout, string api)Refuses a per-call step timeout below zero as INVALID_ARGUMENT (upstream’s checkStepTimeout; a TimeSpan is
always a finite number of milliseconds, so only the sign is left to check). Zero means no step deadline: the step waits until the
running phase’s deadline (the test timeout in the body).
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
TimeSpan? | |
api |
string |
IsOperationTimeout(Exception)
Section titled “IsOperationTimeout(Exception)”public static bool IsOperationTimeout(Exception cause)Whether <code class=“paramref”>cause</code> is the engine’s OPERATION_TIMEOUT, bare or wrapped by the locator failure it was translated into (upstream’s isOperationTimeout).
Parameters
| Name | Type | Description |
|---|---|---|
cause |
Exception |
Returns: bool
Link(CancellationToken, CancellationToken)
Section titled “Link(CancellationToken, CancellationToken)”public static CancellationToken Link(CancellationToken caller, CancellationToken session)The token a call runs under: the caller’s token, ended also by the session’s. No source is made when one token already stands for both, so a call does not leave a registration on the session token. When both can cancel and differ, the linked source lives until either token ends.
Parameters
| Name | Type | Description |
|---|---|---|
caller |
CancellationToken | |
session |
CancellationToken |
Returns: CancellationToken
PollConditionAsync(PollConditionOptions)
Section titled “PollConditionAsync(PollConditionOptions)”public static Task PollConditionAsync(PollConditionOptions options)Polls a condition until it holds (or, when negated, until its negation has held continuously for the negation grace window), throwing the caller’s error at the deadline. No sleep runs past the deadline, so the last read starts at it and never sees a state that arrived later. A negation holds from the moment the read that first saw it was issued, so a slow read counts toward the window. A budget shorter than the window still has to be satisfiable: the negation then only needs to hold for the whole budget, and passes at the deadline on what it has seen, since a read past the deadline has no budget left. A read the deadline cut off (see CutOff(Exception)) after an earlier one completed saw nothing: the poll ends there, and a negation passes if it had held long enough by then.
Parameters
| Name | Type | Description |
|---|---|---|
options |
PollConditionOptions |
Returns: Task
Sleep(TimeSpan, TimeProvider, CancellationToken)
Section titled “Sleep(TimeSpan, TimeProvider, CancellationToken)”public static Task Sleep(TimeSpan duration, TimeProvider clock, CancellationToken cancellationToken = default)Waits for <code class=“paramref”>duration</code> on <code class=“paramref”>clock</code> (upstream’s sleep). A cancel rejects with CANCELLED,
immediately when it was already cancelled.
Parameters
| Name | Type | Description |
|---|---|---|
duration |
TimeSpan | |
clock |
TimeProvider | |
cancellationToken |
CancellationToken |
Returns: Task
StepBudget(TimeSpan?, string, TimeSpan, Deadline?, TimeProvider)
Section titled “StepBudget(TimeSpan?, string, TimeSpan, Deadline?, TimeProvider)”public static TimeSpan StepBudget(TimeSpan? timeout, string api, TimeSpan fallback, Deadline? phase, TimeProvider clock)StepDeadline as a budget, for a call that hands one to the engine: what is left of the deadline, at least 1 ms and
at most Unbounded.
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
TimeSpan? | |
api |
string | |
fallback |
TimeSpan | |
phase |
Deadline | |
clock |
TimeProvider |
Returns: TimeSpan
StepDeadline(TimeSpan?, string, TimeSpan, Deadline?, TimeProvider)
Section titled “StepDeadline(TimeSpan?, string, TimeSpan, Deadline?, TimeProvider)”public static Deadline StepDeadline(TimeSpan? timeout, string api, TimeSpan fallback, Deadline? phase, TimeProvider clock)The deadline of a step on a call’s own <code class=“paramref”>timeout</code> (upstream’s stepTimeout, capped by the phase as
Deadline.min does): the timeout, or <code class=“paramref”>fallback</code> when none is given, from now. Zero sets no deadline of its
own, so <code class=“paramref”>phase</code> alone bounds it; with no phase it is Never.
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
TimeSpan? | |
api |
string | |
fallback |
TimeSpan | |
phase |
Deadline | |
clock |
TimeProvider |
Returns: Deadline
WithTimeout<T>(Task<T>, TimeSpan, Func<Exception>)
Section titled “WithTimeout<T>(Task<T>, TimeSpan, Func<Exception>)”public static Task<T> WithTimeout<T>(Task<T> work, TimeSpan timeout, Func<Exception> onTimeout)Races <code class=“paramref”>work</code> against a timeout; on timeout throws what <code class=“paramref”>onTimeout</code> builds (upstream’s
withTimeout). An infinite timeout sets no timer.
Type parameters
| Name | Description |
|---|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
work |
Task<T> | |
timeout |
TimeSpan | |
onTimeout |
Func<Exception> |
Returns: Task<T>
WithinCleanupBudget(Task, CancellationToken, TimeSpan)
Section titled “WithinCleanupBudget(Task, CancellationToken, TimeSpan)”public static Task WithinCleanupBudget(Task work, CancellationToken abort, TimeSpan timeout)Best-effort cleanup (upstream’s withinCleanupBudget): returns when <code class=“paramref”>work</code> settles, when <code class=“paramref”>abort</code>
fires, or after <code class=“paramref”>timeout</code>, and absorbs the work’s failure, so a cleanup never fails the attempt it closes.
Parameters
| Name | Type | Description |
|---|---|---|
work |
Task | |
abort |
CancellationToken | |
timeout |
TimeSpan |
Returns: Task