Class PendingNameRequests
The client's name requests of one kind: who is waiting on which ID, which IDs are due to be sent, and when each was last sent. Pure bookkeeping: no network, no Unity, main thread only.
public sealed class PendingNameRequests
- Inheritance
-
PendingNameRequests
- Inherited Members
Remarks
Coalesced, not sent per ask. Asking for a name used to send one request per ID the moment it was asked for, so opening a 100-member roster sent 100 requests in one frame (hot-path audit M18). An ask now only queues its ID; TakeBatch(double, int, List<long>) hands out the queue a batch at a time, and the caller sends each batch as one request.
Sent again on a later ask, never on its own. The server answers a request over its connection's budget with nothing, and a request sent to a scene server the client has since left is never answered either. An ID still waiting RetrySeconds after it was sent is queued again by the next ask for it, so a lost request costs one retry window and not the session. Nothing re-sends by timer: a name nobody asks for again is not worth the traffic.
"No such entity" is an answer. ResolveMissing(long, double) drops the callbacks that were waiting (they captured UI rows and characters, and would otherwise be held for the session while every later ask appended to the chain) and holds the ID's retry window, so a caller that asks for a deleted character every frame costs one request per window.
Constructors
PendingNameRequests(double)
Creates an empty set of requests.
public PendingNameRequests(double retrySeconds)
Parameters
retrySecondsdoubleSee RetrySeconds.
Properties
QueuedCount
IDs due to go out in the next batch.
public int QueuedCount { get; }
Property Value
RetrySeconds
Seconds after it was sent (or answered "no such entity") before the next ask for an ID sends it again.
public double RetrySeconds { get; }
Property Value
WaitingCount
IDs something is waiting on.
public int WaitingCount { get; }
Property Value
Methods
Clear()
Forgets everything.
public void Clear()
Request(long, Action<string>, double)
Records an ask for an ID's name, and queues the ID to be sent if it is due.
public bool Request(long id, Action<string> callback, double now)
Parameters
idlongThe ID whose name is wanted.
callbackAction<string>Receives the name when it arrives. Combined with any already waiting.
nowdoubleThe current time, in seconds.
Returns
- bool
True if the ID was queued by this ask.
Resolve(long, out Action<string>)
A name arrived: hands back everything that was waiting on it, and forgets the ID.
public bool Resolve(long id, out Action<string> callbacks)
Parameters
Returns
- bool
True if anything was waiting.
ResolveMissing(long, double)
The server looked and there is no such entity: drops what was waiting without calling it, and holds the ID's retry window from now.
public bool ResolveMissing(long id, double now)
Parameters
Returns
- bool
True if anything was waiting.
TakeBatch(double, int, List<long>)
Takes up to max queued IDs to send now, and stamps each as sent.
The rest stay queued, in order, for the next call.
public int TakeBatch(double now, int max, List<long> into)
Parameters
nowdoubleThe current time, in seconds.
maxintMost IDs to take.
intoList<long>Receives the IDs. Not cleared first.
Returns
- int
The number taken.