-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIDeadline.cs
More file actions
72 lines (67 loc) · 3.64 KB
/
Copy pathIDeadline.cs
File metadata and controls
72 lines (67 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
namespace CanKit.Pro.Reliability
{
/// <summary>
/// A single armed deadline (SRS FR-RAW-050). A deadline starts <c>Pending</c> and resolves
/// exactly once into one of three terminal outcomes: it <b>expires</b> (its <c>onExpired</c>
/// callback fired), it is <b>completed</b> (the awaited transition finished in time), or it is
/// <b>cancelled</b> (disposed).
/// </summary>
/// <remarks>
/// The three terminal outcomes are mutually exclusive under normal operation: whichever of the
/// expiry callback, <see cref="Complete"/>, or <see cref="IDisposable.Dispose"/> reaches the internal state
/// field first "wins" the transition out of <c>Pending</c>, and the others become no-ops. This
/// lets a caller (e.g. a UDS client tracking a P2 window) ask "did I complete before the
/// deadline fired?" via <see cref="Complete"/>'s return value.
/// <para>
/// <b>One case resolves into none of the three</b>: if the owning actor is disposed while the
/// deadline is still <c>Pending</c>, the actor discards its not-yet-due callbacks, so the
/// expiry can never fire and all three flags stay false forever — indistinguishable from a
/// healthy pending deadline. Reporting that state would take a fourth flag (or an event) on
/// this interface, which existing implementers could not absorb without a break, so it is
/// documented rather than signalled: tie deadline lifetime to actor lifetime, i.e. resolve
/// outstanding deadlines with <see cref="Complete"/>/<see cref="IDisposable.Dispose"/> before
/// disposing the actor they were armed on. <see cref="Rearm"/> is the one operation that does
/// detect it, because it has to talk to the actor: it throws
/// <see cref="ObjectDisposedException"/> and forces the deadline to <c>Cancelled</c>.
/// </para>
/// </remarks>
public interface IDeadline : IDisposable
{
/// <summary>
/// True once the deadline's timeout elapsed and its <c>onExpired</c> callback won the race
/// to fire.
/// </summary>
bool IsExpired { get; }
/// <summary>
/// True once <see cref="Complete"/> won the race, i.e. the awaited transition finished
/// before the timeout.
/// </summary>
bool IsCompleted { get; }
/// <summary>
/// True once the deadline was cancelled via <see cref="IDisposable.Dispose"/> before it
/// expired or completed.
/// </summary>
bool IsCancelled { get; }
/// <summary>
/// Extends (or shortens) a still-<c>Pending</c> deadline to a new timeout measured from now,
/// e.g. an ISO-TP receiver refreshing N_Cr on each consecutive frame.
/// </summary>
/// <param name="timeout">New time until expiry, measured from now. Must be >= <see cref="TimeSpan.Zero"/>.</param>
/// <returns>
/// True if the deadline was still <c>Pending</c> and has been re-armed; false if it had
/// already expired, completed, or been cancelled (in which case nothing changes).
/// </returns>
bool Rearm(TimeSpan timeout);
/// <summary>
/// Marks a still-<c>Pending</c> deadline as completed, cancelling its pending expiry.
/// </summary>
/// <returns>
/// True if this call won the race and moved the deadline from <c>Pending</c> to
/// <c>Completed</c>; false if the deadline had already expired, completed, or been cancelled
/// (idempotent no-op). The return value is the caller's answer to "did I finish before the
/// deadline fired?".
/// </returns>
bool Complete();
}
}