UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Async.h File Reference

Go to the source code of this file.

Classes

class  FAsyncGraphTaskBase
 
class  TAsyncGraphTask< ResultType >
 
class  TAsyncRunnable< ResultType >
 
class  TAsyncQueuedWork< ResultType >
 
struct  FAsyncThreadIndex
 

Enumerations

enum class  EAsyncExecution {
  TaskGraph , TaskGraphMainThread , TaskGraphMainTick , Thread ,
  ThreadIfForkSafe , ThreadPool
}
 

Functions

template<typename ResultType , typename CallableType >
void SetPromise (TPromise< ResultType > &Promise, CallableType &&Callable)
 
template<typename CallableType >
void SetPromise (TPromise< void > &Promise, CallableType &&Callable)
 
template<typename CallableType >
auto Async (EAsyncExecution Execution, CallableType &&Callable, TUniqueFunction< void()> CompletionCallback=nullptr) -> TFuture< decltype(Forward< CallableType >(Callable)())>
 
template<typename CallableType >
auto AsyncPool (FQueuedThreadPool &ThreadPool, CallableType &&Callable, TUniqueFunction< void()> CompletionCallback=nullptr, EQueuedWorkPriority InQueuedWorkPriority=EQueuedWorkPriority::Normal) -> TFuture< decltype(Forward< CallableType >(Callable)())>
 
template<typename CallableType >
auto AsyncThread (CallableType &&Callable, uint32 StackSize=0, EThreadPriority ThreadPri=TPri_Normal, TUniqueFunction< void()> CompletionCallback=nullptr) -> TFuture< decltype(Forward< CallableType >(Callable)())>
 
CORE_API void AsyncTask (ENamedThreads::Type Thread, TUniqueFunction< void()> Function)
 

Enumeration Type Documentation

◆ EAsyncExecution

enum class EAsyncExecution
strong

Enumerates available asynchronous execution methods.

Enumerator
TaskGraph 

Execute in Task Graph (for short running tasks).

TaskGraphMainThread 

Execute in Task Graph on the main thread (for short running tasks that are safe to run anywhere including inside other waits). Note: this could end up running inside the GC or inside PostLoads, code with delegates that can't be known to be safe in advance should opt for TaskGraphMainTick instead.

TaskGraphMainTick 

Execute inside a Tick on the main thread (for short running tasks that needs to run at a safe place).

Thread 

Execute in separate thread if supported (for long running tasks).

ThreadIfForkSafe 

Execute in separate thread if supported or supported post fork (see FForkProcessHelper::CreateThreadIfForkSafe) (for long running tasks).

ThreadPool 

Execute in global queued thread pool.

Function Documentation

◆ Async()

template<typename CallableType >
auto Async ( EAsyncExecution  Execution,
CallableType &&  Callable,
TUniqueFunction< void()>  CompletionCallback = nullptr 
) -> TFuture<decltype(Forward<CallableType>(Callable)())>

Execute a given function asynchronously.

Usage examples:

// using global function int TestFunc() { return 123; }

TUniqueFunction<int()> Task = TestFunc(); auto Result = Async(EAsyncExecution::Thread, Task);

// using lambda TUniqueFunction<int()> Task = []() { return 123; }

auto Result = Async(EAsyncExecution::Thread, Task);

// using inline lambda auto Result = Async(EAsyncExecution::Thread, []() { return 123; }

Parameters
CallableTypeThe type of callable object.
ExecutionThe execution method to use, i.e. on Task Graph or in a separate thread.
FunctionThe function to execute.
CompletionCallbackAn optional callback function that is executed when the function completed execution.
Returns
A TFuture object that will receive the return value from the function.

◆ AsyncPool()

template<typename CallableType >
auto AsyncPool ( FQueuedThreadPool ThreadPool,
CallableType &&  Callable,
TUniqueFunction< void()>  CompletionCallback = nullptr,
EQueuedWorkPriority  InQueuedWorkPriority = EQueuedWorkPriority::Normal 
) -> TFuture<decltype(Forward<CallableType>(Callable)())>

Execute a given function asynchronously on the specified thread pool.

Parameters
CallableTypeThe type of callable object.
ThreadPoolThe thread pool to execute on.
FunctionThe function to execute.
CompletionCallbackAn optional callback function that is executed when the function completed execution.
Returns
A TFuture object that will receive the return value from the function.

◆ AsyncTask()

CORE_API void AsyncTask ( ENamedThreads::Type  Thread,
TUniqueFunction< void()>  Function 
)

Convenience function for executing code asynchronously on the Task Graph.

Parameters
ThreadThe name of the thread to run on.
FunctionThe function to execute.

◆ AsyncThread()

template<typename CallableType >
auto AsyncThread ( CallableType &&  Callable,
uint32  StackSize = 0,
EThreadPriority  ThreadPri = TPri_Normal,
TUniqueFunction< void()>  CompletionCallback = nullptr 
) -> TFuture<decltype(Forward<CallableType>(Callable)())>

Execute a given function asynchronously using a separate thread.

Parameters
CallableTypeThe type of callable object.
FunctionThe function to execute.
StackSizestack space to allocate for the new thread
ThreadPrithread priority
CompletionCallbackAn optional callback function that is executed when the function completed execution.
Returns
A TFuture object that will receive the return value from the function.

◆ SetPromise() [1/2]

template<typename ResultType , typename CallableType >
void SetPromise ( TPromise< ResultType > &  Promise,
CallableType &&  Callable 
)
inline

Template for setting a promise value from a callable.

◆ SetPromise() [2/2]

template<typename CallableType >
void SetPromise ( TPromise< void > &  Promise,
CallableType &&  Callable 
)
inline