Skip to content

Instantly share code, notes, and snippets.

@hxhb
Created July 24, 2019 16:43
Show Gist options
  • Save hxhb/374b33fd6fcbe38868f095f4c787755e to your computer and use it in GitHub Desktop.
Save hxhb/374b33fd6fcbe38868f095f4c787755e to your computer and use it in GitHub Desktop.
UE4 FRunnable Wrapper class.
#pragma once
#include "HAL/Runnable.h"
#include "HAL/RunnableThread.h"
class FThread : public FRunnable
{
public:
using FCallback = TFunction<void()>;
explicit FThread(const TCHAR *pThreadName, const FCallback& pCallback)
:mCallback(pCallback)
{
mThread = FRunnableThread::Create(this,pThreadName);
}
void Join()
{
mThread->WaitForCompletion();
}
virtual uint32 Run()override
{
mCallback();
return 0;
}
virtual void Exit()override
{
}
private:
FCallback mCallback;
FRunnableThread* mThread;
private:
FThread(const FThread&) = delete;
FThread& operator=(const FThread&) =delete;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment