-
Notifications
You must be signed in to change notification settings - Fork 240
/
CULambdaRunnable.h
72 lines (55 loc) · 2.03 KB
/
CULambdaRunnable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2018-current Getnamo. All Rights Reserved
#pragma once
#include "Engine/LatentActionManager.h"
#include "LatentActions.h"
#include "Async/TaskGraphInterfaces.h"
/** A simple latent action where we don't hold the value, expect capturing value in lambdas */
class COREUTILITY_API FCULatentAction : public FPendingLatentAction
{
public:
TFunction<void()> OnCancelNotification = nullptr;
/** Note that you need to use the resulting call to cleanly exit */
static FCULatentAction* CreateLatentAction(struct FLatentActionInfo& LatentInfo, UObject* WorldContext);
FCULatentAction(const FLatentActionInfo& LatentInfo);
virtual void UpdateOperation(FLatentResponse& Response) override;
void Call();
void Cancel();
virtual void NotifyObjectDestroyed() override;
virtual void NotifyActionAborted() override;
#if WITH_EDITOR
virtual FString GetDescription() const override;
#endif
const FName ExecutionFunction;
const int32 OutputLink;
const FWeakObjectPtr CallbackTarget;
private:
bool Called;
};
/**
* Convenience wrappers for common thread/task work flow. Run background task on thread, callback via task graph on game thread
*/
class COREUTILITY_API FCULambdaRunnable
{
public:
/**
* Runs the passed lambda on the background thread, new thread per call
*/
static void RunLambdaOnBackGroundThread(TFunction< void()> InFunction);
/**
* Runs the passed lambda on the background thread pool
*/
static void RunLambdaOnBackGroundThreadPool(TFunction< void()> InFunction);
/**
* Runs a short lambda on the game thread via task graph system
*/
static FGraphEventRef RunShortLambdaOnGameThread(TFunction< void()> InFunction);
/**
* Runs a short lambda on background thread via task graph system
*/
static FGraphEventRef RunShortLambdaOnBackGroundTask(TFunction< void()> InFunction);
/**
* Runs a thread with idle for duration before calling back on game thread.
* Due to context cost recommended for >0.1sec durations.
*/
static void SetTimeout(TFunction<void()>OnDone, float DurationInSec, bool bCallbackOnGameThread = true);
};