WorkerQuery
Sends one game-defined request to several workers and collects their replies.
Nebula · Packages/com.1by3.nebula/Runtime/Worker/WorkerQuery.cspublic sealed class WorkerQuery : IDisposableSends one game-defined request to several workers and collects their replies. Tracks the request id, workers that have not replied, deadline, and completion callback. The receiving handler reads the request payload and writes a reply. WorkerQuery adds the request id to both messages.
A target that is not connected is skipped (it never counts as awaited). Sending to this worker's own index answers synchronously, like any worker message to oneself. A reply for an unknown or already completed request is counted in RepliesLate and dropped. Call Update once a frame to expire requests whose deadline passed; the completion callback then runs with false.
Constructors
WorkerQuery
public WorkerQuery(IWorkerMessaging worker, ushort requestKind, ushort replyKind, RequestHandler onRequest, Func<float> clock = null);| Parameter | Description |
|---|---|
worker | The worker to send and receive through. |
requestKind | Worker message kind of the question. |
replyKind | Worker message kind of the answer. |
onRequest | Answers a question on this worker, or null when this worker only asks. |
clock | Seconds, for the deadline; Time.unscaledTime by default. |
Properties
RequestsSent
public int RequestsSent { get; }Requests sent to at least one worker.
RequestsAnswered
public int RequestsAnswered { get; }Requests answered on this side.
RepliesReceived
public int RepliesReceived { get; }Replies received in time.
RepliesTimedOut
public int RepliesTimedOut { get; }Workers that had not answered when a request expired.
RepliesLate
public int RepliesLate { get; }Replies that arrived after their request expired, or for an id never sent.
PendingCount
public int PendingCount { get; }Requests still waiting for at least one worker.
Methods
Send
public uint Send(IEnumerable<ushort> targets, Action<NetworkWriter> write, ReplyHandler onReply, Action<bool> onComplete, float timeoutSeconds);Ask targets (worker indices; duplicates and unreachable workers are skipped). Each reply invokes onReply; onComplete runs once, with true when every asked worker answered and false when timeoutSeconds passed first. When nobody could be asked it runs immediately with true. Returns the request id (0 when nobody was asked).
Cancel
public bool Cancel(uint id);Forget request id; its callbacks never run. True when it was still pending.
Update
public void Update();Expire requests whose deadline passed, completing each with false. Call once a frame.
Dispose
public void Dispose();Unregister both handlers; pending requests are dropped without callbacks.
Nested types
RequestHandler
public delegate void RequestHandler(string fromWorkerId, ushort fromWorkerIndex, NetworkReader request, NetworkWriter reply);Handles a request on the receiving worker: read request, write the answer into reply.
ReplyHandler
public delegate void ReplyHandler(string fromWorkerId, ushort fromWorkerIndex, NetworkReader reply);Handles one reply on the asking worker.