EN 中文
Back to Overview

LiteRtLm_WaitUntilDone

Engine heartbeat drive interface. Blocks the current thread and pumps asynchronous computation tasks. It is the sole bridge connecting "task submission" and "result callbacks."

01. Engine Crankshaft Drive Principle

graph TD Thread[Background Heartbeat Thread] -->|Loop Call| API[WaitUntilDone] API -->|1. Poll| GPU[GPU Command Queue] GPU -->|2. Event| API API -->|3. Trigger| Callback[LiteRtLmCallback] Callback -->|4. Resume| Thread
Core Design Philosophy: The DLL does not forcibly create background threads; instead, it hands the "driving authority" to the host. If this function is not called in a loop, tokens produced by the GPU will accumulate in internal queues, and callbacks will never be dispatched.

02. Parameter & Return Value Definition

int LiteRtLm_WaitUntilDone(void* engine_ptr, int timeout_sec);
Param/ReturnDescription
engine_ptr Handle to the engine instance to drive.
timeout_sec Timeout for a single blocking call. Set to 0 for default timeout (typically 600 seconds).
Return Value (int) Status Codes:
0: All inference tasks completed normally.
1: Single block timed out, but tasks are still in progress.
-1: Fatal internal engine error occurred.

03. Typical Background Driving Loop (Worker Thread)

// Runs in an independent background thread
void UMyAiSubsystem::InferenceWorker() {
    while (bIsRunning) {
        // Block and wait for token production
        int Result = LiteRtLm_WaitUntilDone(EngineHandle, 1);
        
        if (Result == 0) {
            // All tasks done, sleep to save CPU
            FPlatformProcess::Sleep(0.1f);
        } else if (Result < 0) {
            UE_LOG(LogTemp, Error, TEXT("Engine Heartbeat Lost!"));
            break;
        }
        // Result == 1 means still generating, continue next loop
    }
}