Skip to main content
Version: 5.11.6

How To Use SendQueue

This is a guide on how to initialize, stop, resume, and use other logic on SendQueue and its threads.

SendQueueMgr

By using the following methods, you can easily add all logics, including initialization, stop, and restart, to the game using SendQueueMgr without manually writing a SendQueue logic.
Please refer to the SendQueueMgr developer documentation.

Check whether SendQueue has been initialized

This variable confirms whether SendQueue has been initialized.

IsInitialize -> static bool

// example
if(SendQueue.IsInitialize == false)
{
// Initialize SendQueue
}

Initialize/start SendQueue

This method starts when SendQueue is initialized and creates the thread to be operated.

  • If you start SendQueue by calling the StartSendQueue method, it will call and execute the methods stacked in SendQueue one by one without having to call another method.
  • If you call the method when SendQueue already exists, the existing SendQueue and thread will be removed and a new SendQueue and thread will be created.
  • When registering an exception handler, the relevant substitute will be called when an error occurs within SendQueue.
public delegate void ExceptionEvent(Exception e);
StartSendQueue(bool isEnableLog = true, ExceptionEvent exceptionEvent = null) -> static void

// example
if(SendQueue.IsInitialize == false)
{
// Initialize SendQueue
SendQueue.StartSendQueue(true, ExceptionHandler);
}

void ExceptionHandler(Exception e)
{
// Exception handling
}

Parameters

ValueTypeDescription
isEnableLogboolWhether to display the exceptions and logs generated while the queue is operating
Displays the log using Debug.Log and Debug.LogWarning.
Generally, it is recommended to declare as true.
exceptionEventExceptionEventThe handler used to handle exceptions when they are generated in SendQueue.

Stop SendQueue

Stops and deletes the thread where SendQueue is operating.
Aborts immediately without confirming whether an object remains in the current SendQueue.

  • The thread where SendQueue is operating is a background thread and is removed along with the main thread. Therefore, it may be removed automatically even if the StopQueue method is not called.
  • However, the SendQueue thread may not be deleted if the game is closed under abnormal situations; therefore, it is recommended to call the StopSendQueue() method when closing the game.
  • When registering an exception handler, if SendQueue is stopped, an abort exception is generated and the exception handler is also called.
    ThreadAbortException is an exception generated when the thread is closed; you may ignore it.
    This issue will be fixed later.
In the editor, the StopSendQueue method must be called.
  • Since the main thread is not deleted in the editor environment, the SendQueue thread will not be deleted even by releasing the play button.
  • You must call the SendQueue method from the OnApplicationQuit() method, etc. to perform a proper test.
  • StopSendQueue() -> static void

    // example
    void OnApplicationQuit()
    {
    // When you want to wait when there is a pending request in the queue
    // Check how many methods are in the queue
    while(SendQueue.UnprocessedFuncCount > 0)
    {
    // Process
    }

    SendQueue.StopSendQueue();
    }

    Pause SendQueue

    Pauses the SendQueue operation.
    It is recommended to call this when the game moves to the background or when you want to stop the request.

    PauseSendQueue() -> static void

    // example
    void OnApplicatoinPause(bool isPause)
    {
    if(isPause == true)
    {
    // When the game is paused
    SendQueue.PauseSendQueue();
    }
    }

    Resume SendQueue

    Resumes the paused SendQueue.
    It is recommended to call this when the game is moved from the background to the foreground.

    ResumeSendQueue() -> static void

    // example
    void OnApplicatoinPause(bool isPause)
    {
    if(isPause == false)
    {
    // When the game resumes
    SendQueue.ResumeSendQueue();
    }
    }

    Execute the lambda method declared as a method callback

    According to Unity's policy, Unity's MonoBehavior object can be accessed only from the main thread, not from another thread.
    When a response to a request is received, a callback method is inserted into the callback method queue, and the Poll method executes it.
    In the Poll method, all callback methods that exist in the callback method queue at the current time are retrieved and executed.

    Poll() -> static void

    // example
    // From the Update method of the Unity object or the regularly called coroutine(within 1 second),
    // Call the Poll method.
    void Update()
    {
    SendQueue.Poll();
    }

    Execute a single lambda method declared as a method callback

    The method below performs the same function as the poll method above, but instead of executing all callback methods that exist in the callback method queue at the current time, only one callback method is retrieved and executed.
    Between Poll or PollOneResponse, only one method should be called.

    PollOneResponse() -> static void

    // example
    // From the Update method of the Unity object or the regularly called coroutine(within 1 second),
    // Call the PollOneResponse method.
    void Update()
    {
    SendQueue.PollOneResponse();
    }

    Insert a method in SendQueue

    Inserts the BACKND method to be called in SendQueue.
    If SendQueue is operating, the inserted methods will be executed by being returned from the thread in the order of their insertions.
    In this case, the callback method to be executed(lambda method provided as a parameter value) as the result of the BACKND method execution will be executed in the main thread via the Poll method.

    Enqueue(Func<BackendReturnObject> BackendFunc, Action<BackendReturnObject> callback) -> static void
    Enqueue<T1>(Func<T1, BackendReturnObject> BackendFunc, T1 GT, Action<BackendReturnObject> callback) -> static void
    Enqueue<T1, T2>(Func<T1, BackendReturnObject> BackendFunc, T1 GT1, T2 GT2, Action<BackendReturnObject> callback) -> static void
    Enqueue<T1, T2, T3>(Func<T1, BackendReturnObject> BackendFunc, , T1 GT1, T2 GT2, T3 GT3, Action<BackendReturnObject> callback) -> static void
    Enqueue<T1, T2, T3, T4>(Func<T1, BackendReturnObject> BackendFunc, , T1 GT1, T2 GT2, T3 GT3, T4 GT4 Action<BackendReturnObject> callback) -> static void
    Enqueue<T1, T2, T3, T4, T5>(Func<T1, BackendReturnObject> BackendFunc, , T1 GT1, T2 GT2, T3 GT3, T4 GT4, T5 GT5 Action<BackendReturnObject> callback) -> static void

    // example
    SendQueue.Enqueue(Backend.GameInfo.GetPublicContents, "publicTable", callback =>
    {
    // Post-process
    });

    Size of the current SendQueue

    Returns the number of pending methods in SendQueue.

    UnprocessedFuncCount -> static int

    // example
    int count = SendQueue.UnprocessedFuncCount;