Skip to content

Instantly share code, notes, and snippets.

@dorgonman
Created August 30, 2018 13:56
Show Gist options
  • Save dorgonman/3bebd7ed09b67972ff87446023f04c21 to your computer and use it in GitHub Desktop.
Save dorgonman/3bebd7ed09b67972ff87446023f04c21 to your computer and use it in GitHub Desktop.
FAutoDeleteAsyncTask
class FMyWorldAsyncChecker : public FNonAbandonableTask
{
public:
/**
* Constructor for async task
* @param InDataDeriver plugin to produce cache key and in the event of a miss, return the data.
* @param InCacheKey Complete cache key for this data.
**/
FMyWorldAsyncChecker()
{
}
/** Async worker that checks the cache backend and if that fails, calls the deriver to build the data and then puts the results to the cache **/
void DoWork()
{
while (GEngine->GetWorldContexts().Num() == 0)
{
}
AsyncTask(ENamedThreads::GameThread, []()
{
UE_LOG(LogTemp, Log, TEXT("finished"));
});
};
FORCEINLINE TStatId GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(FMyWorldAsyncChecker, STATGROUP_ThreadPoolAsyncTasks);
};
};
void AHorizonTweenDemoGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
{
Super::InitGame(MapName, Options, ErrorMessage);
auto worldContexts = GEngine->GetWorldContexts();
worldContexts[0].LastURL.Port;
FAutoDeleteAsyncTask<FMyWorldAsyncChecker>* AsyncTask = new FAutoDeleteAsyncTask<FMyWorldAsyncChecker>();
AsyncTask->StartBackgroundTask();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment