25 #include <seastar/core/future.hh>
26 #include <seastar/util/concepts.hh>
27 #include <seastar/util/defer.hh>
36 template <typename Object>
37 concept closeable = requires (Object o) {
38 { o.close() } SEASTAR_DEFERRED_ACTION_NOEXCEPT -> std::same_as<future<>>;
49 template <typename Object>
50 SEASTAR_CONCEPT( requires closeable<Object> )
52 std::reference_wrapper<Object> _obj;
55 void do_close() noexcept {
58 _obj.get().close().get();
75 _closed = std::exchange(x._closed,
true);
95 template <
typename Closeable,
typename Func>
97 requires closeable<Closeable> && std::invocable<Func, Closeable&> &&
98 std::is_nothrow_move_constructible_v<Closeable> && std::is_nothrow_move_constructible_v<Func>
100 inline futurize_t<std::invoke_result_t<Func, Closeable&>>
101 with_closeable(Closeable&& obj, Func func) noexcept {
102 return do_with(std::move(obj), [func = std::move(func)] (Closeable& obj)
mutable {
103 return futurize_invoke(func, obj).finally([&obj] {
110 template <typename Object>
111 concept stoppable = requires (Object o) {
112 { o.stop() } SEASTAR_DEFERRED_ACTION_NOEXCEPT -> std::same_as<future<>>;
123 template <typename Object>
124 SEASTAR_CONCEPT( requires stoppable<Object> )
126 std::reference_wrapper<Object> _obj;
127 bool _stopped =
false;
129 void do_stop() noexcept {
132 _obj.get().stop().get();
149 _stopped = std::exchange(x._stopped,
true);
169 template <
typename Stoppable,
typename Func>
171 requires stoppable<Stoppable> && std::invocable<Func, Stoppable&> &&
172 std::is_nothrow_move_constructible_v<Stoppable> && std::is_nothrow_move_constructible_v<Func>
174 inline futurize_t<std::invoke_result_t<Func, Stoppable&>>
175 with_stoppable(Stoppable&& obj, Func func) noexcept {
176 return do_with(std::move(obj), [func = std::move(func)] (Stoppable& obj)
mutable {
177 return futurize_invoke(func, obj).finally([&obj] {
Definition: closeable.hh:51
void close_now() noexcept
Close obj once now.
Definition: closeable.hh:83
void cancel() noexcept
Definition: closeable.hh:90
deferred_close & operator=(deferred_close &&x) noexcept
Definition: closeable.hh:72
deferred_close(deferred_close &&x) noexcept
Definition: closeable.hh:67
~deferred_close()
Destruct the deferred_close object and auto-close obj.
Definition: closeable.hh:79
deferred_close(Object &obj) noexcept
Definition: closeable.hh:64
Definition: closeable.hh:125
deferred_stop(Object &obj) noexcept
Definition: closeable.hh:138
void stop_now() noexcept
Stop obj once now.
Definition: closeable.hh:157
deferred_stop(deferred_stop &&x) noexcept
Definition: closeable.hh:141
deferred_stop & operator=(deferred_stop &&x) noexcept
Definition: closeable.hh:146
~deferred_stop()
Destruct the deferred_stop object and auto-stop obj.
Definition: closeable.hh:153
void cancel() noexcept
Definition: closeable.hh:164
auto do_with(T1 &&rv1, T2 &&rv2, More &&... more) noexcept
Definition: do_with.hh:135
Seastar API namespace.
Definition: abort_on_ebadf.hh:26