Last active
August 29, 2015 14:24
-
-
Save unktomi/9d95a254287fef197b01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* One-shot continuation built on top of FPendingLatentAction | |
*/ | |
template <class T> class FContinueAction : public FPendingLatentAction | |
{ | |
bool Called; | |
const FName ExecutionFunction; | |
const int32 OutputLink; | |
const FWeakObjectPtr CallbackTarget; | |
T &Result; | |
public: | |
virtual void Call(const T &Value) { | |
Result = Value; | |
Called = true; | |
} | |
FContinueAction(T& ResultParam, const FLatentActionInfo& LatentInfo) : | |
Called(false) | |
, Result(ResultParam) | |
, ExecutionFunction(LatentInfo.ExecutionFunction) | |
, OutputLink(LatentInfo.Linkage) | |
, CallbackTarget(LatentInfo.CallbackTarget) | |
{ | |
} | |
virtual void UpdateOperation(FLatentResponse& Response) override | |
{ | |
Response.FinishAndTriggerIf(Called, ExecutionFunction, OutputLink, CallbackTarget); | |
} | |
}; | |
// Pseudocode Example of use in a modified MediaPlayer that handles operations asynchronously | |
UFUNCTION(BlueprintCallable, Category = "Media|MediaPlayer", meta = (Latent, WorldContext = "WorldContextObject", LatentInfo = "LatentInfo")) | |
virtual void OpenUrlLatently(const FString& Url, bool &Result, UObject* WorldContextObject, struct FLatentActionInfo LatentInfo) | |
{ | |
FContinueAction<bool> *ContinueAction = 0; | |
if (UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject)) | |
{ | |
FLatentActionManager& LatentActionManager = World->GetLatentActionManager(); | |
if (LatentActionManager.FindExistingAction<FContinueAction<UVaRestJsonObject>>(LatentInfo.CallbackTarget, LatentInfo.UUID) == NULL) | |
{ | |
LatentActionManager.AddNewAction(LatentInfo.CallbackTarget, LatentInfo.UUID, ContinueAction = new FContinueAction<bool>(Result, LatentInfo)); | |
// Arrange to call ContinueAction asynchronously when the result of OpenUrl is known | |
DoOpenUrl(Url); | |
} else { | |
// handle duplicate | |
} | |
} else { | |
// handle no world | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment