From bc99e701b7dfc9a3e8fa22de9ba793d736abeded Mon Sep 17 00:00:00 2001 From: syntheticmagus <33846034+syntheticmagus@users.noreply.github.com> Date: Mon, 13 Sep 2021 19:48:09 -0700 Subject: [PATCH] Simple handle unexpected pattern. --- Source/Shared/arcana/threading/task.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Source/Shared/arcana/threading/task.h b/Source/Shared/arcana/threading/task.h index 8deed68..3525e7a 100644 --- a/Source/Shared/arcana/threading/task.h +++ b/Source/Shared/arcana/threading/task.h @@ -119,6 +119,18 @@ namespace arcana return factory.to_return; } + template + void handle_unexpected(CallableT&& handler, cancellation& token) + { + this->then(inline_scheduler, token, [handler = std::forward(handler)](const expected& e) + { + if (e.has_error()) + { + handler(e.error()); + } + }); + } + private: explicit task(payload_ptr payload) : m_payload{ std::move(payload) }