Class PendingReplyGuard
Watchdog for a UI control that has been disabled while waiting for a server reply.
public sealed class PendingReplyGuard
- Inheritance
-
PendingReplyGuard
- Inherited Members
Remarks
Every login-flow panel works the same way: it disables its action button, sends a request, and re-enables the button when the reply arrives. That is correct right up until the reply never arrives, at which point the panel is a dead end — the player is looking at a screen whose only control does nothing, with no error and no explanation.
The reply can go missing for reasons the client cannot see and cannot fix: the server's main-thread queue rejecting the action at capacity, a handler throwing before it sends, or the server simply never getting to it. Rather than enumerate those, the panel assumes a reply that has not arrived within DefaultTimeoutSeconds is not coming, hands the control back, and says so.
Re-enabling is deliberately all it does. Nothing is torn down and no connection is dropped, so a late reply is still handled normally when it lands — the panel's own handler re-enables an already-enabled control, which is a no-op.
Fields
DefaultTimeoutSeconds
How long to wait for a reply before handing the control back.
public const float DefaultTimeoutSeconds = 30
Field Value
Remarks
Comfortably longer than any round trip these panels make, including one that has to wait on a database write, so a merely slow server is never mistaken for a silent one. Short enough that a player does not sit in front of a dead button wondering whether the game has stopped responding.
Properties
IsPending
True while a reply is still expected.
public bool IsPending { get; }
Property Value
Methods
Begin(float)
Starts the wait. Call when the control is disabled and the request goes out.
public void Begin(float timeoutSeconds = 30)
Parameters
timeoutSecondsfloatSeconds to wait; defaults to DefaultTimeoutSeconds.
Clear()
Ends the wait. Call when the reply arrives, or when the control is re-enabled for any other reason.
public void Clear()
HasExpired()
Reports whether the wait has just been abandoned.
public bool HasExpired()
Returns
- bool
trueon the single frame the timeout elapses.
Remarks
Self-clearing, so it returns true exactly once per wait and the caller can
drive it straight from a per-frame tick without tracking anything itself.
Refresh(float)
Extends the wait because the server has been heard from.
public void Refresh(float timeoutSeconds = 30)
Parameters
timeoutSecondsfloatSeconds to wait from now.
Remarks
For flows that report progress before they finish — the SRP exchange and the two-factor prompt both send intermediate results — an intermediate message is proof the server is still working, so it should buy the same grace again rather than counting against the original deadline.