Async with value as callback parameter.

Hi there, you’re not far off in your approach however you need to correctly capture the result after the async task has finished. The main issue in your code is that you’re trying to capture the result of result_E.Get() before the future has been resolved, which isn’t valid.

Something along these lines:

void FWortWortWort::DoWork() {
    // Define the task to be executed asynchronously.
    TFunction<FString()> task_E = [this]() { return this->Async_TestE(); };

    // Create a promise to set the result and a future to get the result.
    TPromise<FString> promise_E;
    TFuture<FString> result_E = promise_E.GetFuture();

    // Define the completion callback to handle the result.
    TUniqueFunction<void()> callback = [this, result_E = MoveTemp(result_E)]() mutable {
        FString strYarp = result_E.Get();
        OnTask_E_Completed(strYarp);
    };

    // Run the task asynchronously and fulfill the promise when done.
    Async(EAsyncExecution::ThreadPool, [promise_E = MoveTemp(promise_E), task_E = MoveTemp(task_E), callback = MoveTemp(callback)]() mutable {
        FString result = task_E();
        promise_E.SetValue(result); // Set the result.
        callback(); // Invoke the callback with the result.
    });

    UE_LOG(LogVTSFileManager, Log, TEXT("Some Other Work"));
}

FString FWortWortWort::Async_TestE() {
    UE_LOG(LogVTSFileManager, Log, TEXT("Start Async E"));

    FPlatformProcess::Sleep(2); // Simulate long computation.

    UE_LOG(LogVTSFileManager, Log, TEXT("End Async E"));

    return TEXT("Return Async E");
}

void FWortWortWort::OnTask_E_Completed(FString strValue) {
    UE_LOG(LogVTSFileManager, Log, TEXT("Async E Completed: %s"), *strValue);
}

Hope this helps.