6 #ifndef UTILS_CONCURRENT_BINDING_H 7 #define UTILS_CONCURRENT_BINDING_H 10 #include "EventHandler.h" 27 void Run(
const std::function<T(
void)> &
func)
31 std::bind(&ConcurrentBinding::ParallelFunction,
this,
func)
40 using namespace std::chrono_literals;
41 const auto status = result_.wait_for(0ms);
42 return status != std::future_status::ready;
50 callback_on_finish_ =
func;
54 std::function<void(T)> callback_on_finish_;
55 std::future<T> result_;
57 T ParallelFunction(
const std::function<T(
void)> &
func)
59 const auto result =
func();
64 virtual void ProcessEvent(
const Event *e)
override 66 if (e->id ==
"Finished" && callback_on_finish_ && result_.valid())
68 callback_on_finish_(result_.get());
Default event. Inherit this structure to create custom event.
Definition: EventHandler.h:38
void RegisterEvent(Args... args)
Adds new event to the event queue.
Definition: EventHandler.h:47
Controller for binding asynchronous processes.
Definition: ConcurrentBinding.h:23
Contains common lambda functions.
Definition: Functional.h:12
void Run(const std::function< T(void)> &func)
Execute provided function asynchronously from a caller thread.
Definition: ConcurrentBinding.h:27
General namespace for utilities.
Definition: BulletConversions.h:9
bool IsRunning() const
Check if asynchronous function is still running.
Definition: ConcurrentBinding.h:36
Provides an interface for registering and processing events for inherited classes.
Definition: EventHandler.h:22
void SetCallbackOnFinish(const std::function< void(T)> &func)
Set callback which will be called via PollEvents after asynchronous function is finished.
Definition: ConcurrentBinding.h:48