diff --git a/Source/Shared/arcana/scheduling/state_machine.h b/Source/Shared/arcana/scheduling/state_machine.h index a85c314..731c4e6 100644 --- a/Source/Shared/arcana/scheduling/state_machine.h +++ b/Source/Shared/arcana/scheduling/state_machine.h @@ -34,7 +34,7 @@ namespace arcana stateTasks.StateEntered->complete(expected::make_valid()); - std::shared_ptr listener = std::make_shared(cancel.add_listener([this, &state] + std::shared_ptr listener = std::make_shared(cancel.add_cancellation_requested_listener([this, &state] { cancel_exit(state); })); @@ -74,7 +74,7 @@ namespace arcana stateTasks = completion; } - std::shared_ptr listener = std::make_shared(cancel.add_listener([this, &state] + std::shared_ptr listener = std::make_shared(cancel.add_cancellation_requested_listener([this, &state] { cancel_enter(state); })); diff --git a/Source/Shared/arcana/threading/cancellation.h b/Source/Shared/arcana/threading/cancellation.h index dd1cf3d..51feb68 100644 --- a/Source/Shared/arcana/threading/cancellation.h +++ b/Source/Shared/arcana/threading/cancellation.h @@ -177,7 +177,7 @@ namespace arcana return ticket{ [] {} }; std::function copied; - ticket result{ m_impl->add_listener(callback, copied) }; + ticket result{ m_impl->add_cancellation_requested_listener(callback, copied) }; if (copied) copied(); @@ -233,28 +233,23 @@ namespace arcana cancellation_source(const cancellation_source&) = delete; cancellation_source(cancellation_source&&) = delete; - operator cancellation() - { - return { m_impl }; - } - void cancel(bool blockUntilCompleted = false) { - std::optional> future{}; + std::optional> promise{}; + std::optional ticket{}; if (blockUntilCompleted) { - std::promise promise{}; - future.emplace(promise.get_future()); - auto ticket = add_cancellation_completed_listener([&promise]() { - promise.set_value(); - }); + promise.emplace(); + ticket.emplace(add_cancellation_completed_listener([&promise]() { + promise.value().set_value(); + })); } m_impl->unsafe_cancel(); - if (future) + if (promise) { - future.value().wait(); + promise.value().get_future().wait(); } } }; diff --git a/Source/Shared/arcana/threading/dispatcher.h b/Source/Shared/arcana/threading/dispatcher.h index fbcb4b0..e558d12 100644 --- a/Source/Shared/arcana/threading/dispatcher.h +++ b/Source/Shared/arcana/threading/dispatcher.h @@ -121,7 +121,7 @@ namespace arcana { public: background_dispatcher() - : m_registration{ m_cancellation.add_listener([this] { this->cancelled(); }) } + : m_registration{ m_cancellation.add_cancellation_requested_listener([this] { this->cancelled(); }) } { m_thread = std::thread{ [&]() {