RemoteEventLock::RemoteEventLock(Dispatcher& dispatcher, Event& event) : dispatcher(dispatcher), event(event) { std::mutex mutex; std::condition_variable condition; bool locked = false; dispatcher.remoteSpawn([&]() { while (!event.get()) { event.wait(); } event.clear(); mutex.lock(); locked = true; condition.notify_one(); mutex.unlock(); }); std::unique_lock<std::mutex> lock(mutex); while (!locked) { condition.wait(lock); } }