Table of Contents

Class MainThreadQueueData

Namespace
FishMMO.Server.Implementation
Assembly
FishMMO.Server.dll

Base runtime data container providing a thread-safe main-thread action queue. Async worker threads enqueue actions via Enqueue(), and the main thread drains them via Drain() each frame (typically in OnLateUpdate).

Each system that needs main-thread marshalling should have its own concrete subclass so the DataContainerRegistry creates separate instances per system.

public abstract class MainThreadQueueData : RuntimeDataContainer, IRuntimeDataContainer<INetworkManagerWrapper, ServerManager, NetworkConnection, IRuntimeDataContainer>, IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IRuntimeDataContainer>, IMainThreadQueueData, IRuntimeDataContainer, IServerComponent
Inheritance
MainThreadQueueData
Implements
Derived
Inherited Members

Methods

Clear()

Clears any pending actions without executing them. Called during server data reset.

public override void Clear()

Drain()

Drains all queued actions, executing them on the calling thread. Must be called from the main Unity thread (e.g., in OnLateUpdate). Copies all queued actions under lock, then invokes them outside the lock to minimize lock hold time and avoid re-entrancy issues.

public void Drain()

Drain(int)

Drains up to maxActions queued actions, executing them on the calling thread. Must be called from the main Unity thread (e.g., in OnLateUpdate).

public int Drain(int maxActions)

Parameters

maxActions int

Maximum number of actions to execute in this call. Values <= 0 execute none.

Returns

int

Number of actions executed.

InitializeOnce()

No additional initialization needed — queue is ready at construction.

public override ServerComponentInitializationStatus InitializeOnce()

Returns

ServerComponentInitializationStatus

OnDeinitialize()

Drains remaining actions and releases resources.

protected override void OnDeinitialize()

TryEnqueue(Action)

Thread-safe attempt to enqueue an action to the main Unity thread. Called from async worker threads.

public bool TryEnqueue(Action action)

Parameters

action Action

The action to execute on the main thread.

Returns

bool

true if the action was enqueued; false if the queue is at capacity.