engine
 
载入中...
搜索中...
未找到
Public 成员函数 | 所有成员列表
FAsyncTask< TTask > 模板类 参考

#include <AsyncWork.h>

+ 类 FAsyncTask< TTask > 继承关系图:

Public 成员函数

bool Cancel ()
 Cancel the task, if possible. 更多...
 
void EnsureCompletion (bool bDoWorkOnThisThreadIfNotStarted=true)
 Wait until the job is complete 更多...
 
template<typename Arg0Type , typename... ArgTypes>
 FAsyncTask (Arg0Type &&Arg0, ArgTypes &&... Args)
 Forwarding constructor.
 
bool IsDone ()
 Returns true if the work and TASK has completed, false while it's still in progress. 更多...
 
bool IsIdle () const
 Returns true if the work has not been started or has been completed. 更多...
 
bool IsWorkDone () const
 Returns true if the work has completed, false while it's still in progress. 更多...
 
void StartBackgroundTask (FQueuedThreadPool *InQueuedPool=GThreadPool)
 Queue this task for processing by the background thread pool
 
void StartSynchronousTask ()
 Run this task on this thread 更多...
 
bool WaitCompletionWithTimeout (float TimeLimitSeconds)
 Wait until the job is complete, up to a time limit 更多...
 
 ~FAsyncTask ()
 Destructor, not legal when a task is in process
 

详细描述

template<typename TTask>
class FAsyncTask< TTask >
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();

to just do it now on this thread Check if the task is done :

    if (MyTask->IsDone())
    {
    }

Spinning on IsDone is not acceptable( see EnsureCompletion ), but it is ok to check once a frame. Ensure the task is done, doing the task on the current thread if it has not been started, waiting until completion in all cases.

    MyTask->EnsureCompletion();
    delete Task;
}

成员函数说明

◆ Cancel()

template<typename TTask >
bool FAsyncTask< TTask >::Cancel ( )
inline

Cancel the task, if possible.

Note that this is different than abandoning (which is called by the thread pool at shutdown).

返回
true if the task was canceled and is safe to delete. If it wasn't canceled, it may be done, but that isn't checked here.

◆ EnsureCompletion()

template<typename TTask >
void FAsyncTask< TTask >::EnsureCompletion ( bool  bDoWorkOnThisThreadIfNotStarted = true)
inline

Wait until the job is complete

参数
bDoWorkOnThisThreadIfNotStartedif true and the work has not been started, retract the async task and do it now on this thread

◆ IsDone()

template<typename TTask >
bool FAsyncTask< TTask >::IsDone ( )
inline

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

prior to returning true, it synchronizes so the task can be destroyed or reused

◆ IsIdle()

template<typename TTask >
bool FAsyncTask< TTask >::IsIdle ( ) const
inline

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

NOT to be used for synchronization, but great for check()'s

◆ IsWorkDone()

template<typename TTask >
bool FAsyncTask< TTask >::IsWorkDone ( ) const
inline

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

This does not block and if true, you can use the results. But you can't destroy or reuse the task without IsDone() being true or EnsureCompletion()

◆ StartSynchronousTask()

template<typename TTask >
void FAsyncTask< TTask >::StartSynchronousTask ( )
inline

Run this task on this thread

参数
bDoNowif true then do the job now instead of at EnsureCompletion

◆ WaitCompletionWithTimeout()

template<typename TTask >
bool FAsyncTask< TTask >::WaitCompletionWithTimeout ( float  TimeLimitSeconds)
inline

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

参数
TimeLimitSecondsMust be positive, if you want to wait forever or poll, use a different call.
返回
true if the task is completed

该类的文档由以下文件生成: