FAsyncTask

Insights.

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Async/AsyncWork.h

Include

#include "Async/AsyncWork.h"

Syntax

template<typename TTask>
class FAsyncTask : private IQueuedWork

Remarks

FAsyncTask - template task for jobs queued to thread pools

Sample code:

class ExampleAsyncTask : public FNonAbandonableTask { friend class FAsyncTask<ExampleAsyncTask>;

int32 ExampleData;

ExampleAsyncTask(int32 InExampleData) : ExampleData(InExampleData) { }

void DoWork() { ... do the work here }

FORCEINLINE TStatId GetStatId() const { RETURN_QUICK_DECLARE_CYCLE_STAT(ExampleAsyncTask, STATGROUP_ThreadPoolAsyncTasks); } };

void Example() {

start an example job FAsyncTask<ExampleAsyncTask>* MyTask = new FAsyncTask<ExampleAsyncTask>( 5 ); MyTask->StartBackgroundTask();

or MyTask->StartSynchronousTask();

Constructors

Name Description

Public function

FAsyncTask()

Public function

FAsyncTask

(
    Arg0Type&& Arg0,
    ArgTypes&&... Args
)

Forwarding constructor.

Destructors

Name Description

Public function

~FAsyncTask()

Destructor, not legal when a task is in process

Functions

Name Description

Public function

bool

 

Cancel()

Cancel the task, if possible.

Public function

void

 

EnsureCompletion

(
    bool bDoWorkOnThisThreadIfNotStarte...,
    bool bIsLatencySensitive
)

Wait until the job is complete

Public function Const

EQueuedWorkP...

 

GetPriority()

Public function

TTask &

 

GetTask()

Retrieve embedded user job, not legal to call while a job is in process

Public function Const

const TTask ...

 

GetTask()

Retrieve embedded user job, not legal to call while a job is in process

Public function

bool

 

IsDone()

Returns true if the work and TASK has completed, false while it's still in progress.

Public function Const

bool

 

IsIdle()

Returns true if the work has not been started or has been completed.

Public function Const

bool

 

IsWorkDone()

Returns true if the work has completed, false while it's still in progress.

Public function

bool

 

Reschedule

(
    FQueuedThreadPool* InQueuedPoo...,
    EQueuedWorkPriority InQueuedWorkPri...
)

If not already being processed, will be rescheduled on given thread pool and priority.

Public function

void

 

StartBackgroundTask

(
    FQueuedThreadPool* InQueuedPoo...,
    EQueuedWorkPriority InQueuedWorkPri...,
    EQueuedWorkFlags InQueuedWorkFlags,
    int64 InRequiredMemory
)

Queue this task for processing by the background thread pool

Public function

void

 

StartSynchronousTask

(
    EQueuedWorkPriority InQueuedWorkPri...,
    EQueuedWorkFlags InQueuedWorkFlags,
    int64 InRequiredMemory
)

Run this task on this thread

Public function

bool

 

WaitCompletionWithTimeout

(
    float TimeLimitSeconds
)

Wait until the job is complete, up to a time limit

Overridden from IQueuedWork

Name Description

Public function Virtual Const

int64

 

GetRequiredMemory()

Returns an approximation of the peak memory (in bytes) this task could require during it's execution.