diff --git a/simple_websocket.hpp b/simple_websocket.hpp index 0afac91..45558ce 100644 --- a/simple_websocket.hpp +++ b/simple_websocket.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace SimpleWebSocket { template @@ -287,6 +288,32 @@ namespace SimpleWebSocket { std::variant value_; }; + struct Workflow final { + explicit Workflow(std::function runFn, + std::function successFn, + std::function recoveryFn) + : runFn_(std::move(runFn)) + , successFn_(std::move(successFn)) + , recoveryFn_(std::move(recoveryFn)) + { } + + void runUntilCancelled() { + WorkflowResult workflowResult = runFn_(); + workflowResult.template match(recoveryFn_, successFn_); + + while (!workflowResult.complete()) { + workflowResult = runFn_(); + workflowResult.template match(recoveryFn_, successFn_); + } + } + + private: + const std::function runFn_; + const std::function successFn_; + const std::function recoveryFn_; + }; + + struct ExecutionContext final { ExecutionContext(std::string host, uint16_t port, std::string uri) : host_(std::move(host)), port_(port), uri_(std::move(uri)) {} @@ -316,7 +343,8 @@ namespace SimpleWebSocket { #include #include #include -#include +#include +#include namespace SimpleWebSocket::Poco { constexpr int PING_FRAME = static_cast(::Poco::Net::WebSocket::FRAME_FLAG_FIN) | @@ -384,10 +412,6 @@ namespace SimpleWebSocket::Poco { return Wrapper{::Poco::Net::WebSocket{session, request, response}}; } -#if __has_include() -#include -#include - template inline Wrapper tls_wrapper(const std::string& host, ::Poco::UInt16 port, @@ -399,6 +423,5 @@ namespace SimpleWebSocket::Poco { return Wrapper{::Poco::Net::WebSocket{session, request, response}}; } -#endif } #endif \ No newline at end of file