Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Outcome.hpp
1#pragma once
2
3#include "util/async/context/impl/Cancellation.hpp"
4
5#include <concepts>
6#include <future>
7
8namespace util::async {
9
10template <typename RetType, typename StopSourceType>
12
13namespace impl {
14
15template <typename RetType>
16class BasicOperation;
17
23template <typename RetType>
24class BasicOutcome {
25protected:
26 std::promise<RetType> promise_;
27
28public:
29 using DataType = RetType;
30
31 BasicOutcome() = default;
32 BasicOutcome(BasicOutcome&&) = default;
33
34 BasicOutcome(BasicOutcome const&) = delete;
35
41 void
42 setValue(std::convertible_to<RetType> auto&& val)
43 {
44 promise_.set_value(std::forward<decltype(val)>(val));
45 }
46
50 void
52 {
53 promise_.set_value({});
54 }
55
61 [[nodiscard]] std::future<RetType>
63 {
64 return promise_.get_future();
65 }
66};
67
68} // namespace impl
69
75template <typename RetType>
76class Outcome : public impl::BasicOutcome<RetType> {
77public:
85 {
87 }
88};
89
96template <typename RetType, typename StopSourceType>
97class StoppableOutcome : public impl::BasicOutcome<RetType> {
98private:
99 StopSourceType stopSource_;
100
101public:
112
118 [[nodiscard]] StopSourceType&
120 {
121 return stopSource_;
122 }
123};
124
125} // namespace util::async
Unstoppable outcome.
Definition Outcome.hpp:76
impl::BasicOperation< Outcome > getOperation()
Gets the unstoppable operation for this outcome.
Definition Outcome.hpp:84
The future side of async operations that can be stopped.
Definition Operation.hpp:151
Stoppable outcome.
Definition Outcome.hpp:97
StoppableOperation< RetType, StopSourceType > getOperation()
Gets the stoppable operation for this outcome.
Definition Outcome.hpp:108
StopSourceType & getStopSource()
Gets the stop source for this outcome.
Definition Outcome.hpp:119
Definition Operation.hpp:26
Base for all promise side of async operations.
Definition Outcome.hpp:24
void setValue(std::convertible_to< RetType > auto &&val)
Sets the value on the inner promise.
Definition Outcome.hpp:42
std::future< RetType > getStdFuture()
Get the future for the inner promise.
Definition Outcome.hpp:62
void setValue()
Sets the value channel for void operations.
Definition Outcome.hpp:51
This namespace implements an async framework built on top of execution contexts.
Definition AnyExecutionContext.hpp:17