diff --git a/native/cpp/CommonCpp/Tools/WorkerThread.h b/native/cpp/CommonCpp/Tools/WorkerThread.h --- a/native/cpp/CommonCpp/Tools/WorkerThread.h +++ b/native/cpp/CommonCpp/Tools/WorkerThread.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -17,6 +18,7 @@ public: WorkerThread(const std::string name); void scheduleTask(const taskType task); + std::shared_ptr> flushAndBlock(); ~WorkerThread(); }; diff --git a/native/cpp/CommonCpp/Tools/WorkerThread.cpp b/native/cpp/CommonCpp/Tools/WorkerThread.cpp --- a/native/cpp/CommonCpp/Tools/WorkerThread.cpp +++ b/native/cpp/CommonCpp/Tools/WorkerThread.cpp @@ -26,6 +26,18 @@ } } +std::shared_ptr> WorkerThread::flushAndBlock() { + std::shared_ptr> queueBlockade = + std::make_shared>(std::promise()); + std::promise taskStarted; + this->tasks.write(std::make_unique([queueBlockade, &taskStarted]() { + taskStarted.set_value(); + queueBlockade->get_future().get(); + })); + taskStarted.get_future().get(); + return queueBlockade; +} + WorkerThread::~WorkerThread() { this->tasks.blockingWrite(nullptr); try {