Nebula
Worker

WorkerQuery

Sends one game-defined request to several workers and collects their replies.

generated from the sources
public sealed class WorkerQuery : IDisposable

Sends 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);
ParameterDescription
workerThe worker to send and receive through.
requestKindWorker message kind of the question.
replyKindWorker message kind of the answer.
onRequestAnswers a question on this worker, or null when this worker only asks.
clockSeconds, 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.

On this page