26#include <seastar/core/future.hh>
27#include <seastar/util/defer.hh>
35template <
typename Object>
36concept closeable =
requires (Object o) {
37 { o.close() } SEASTAR_DEFERRED_ACTION_NOEXCEPT -> std::same_as<future<>>;
47template <
typename Object>
48requires closeable<Object>
50 std::reference_wrapper<Object> _obj;
53 void do_close()
noexcept {
56 _obj.get().close().get();
73 _closed = std::exchange(x._closed,
true);
93template <closeable Closeable, std::invocable<Closeable&> Func>
94requires std::is_nothrow_move_constructible_v<Closeable> && std::is_nothrow_move_constructible_v<Func>
95inline futurize_t<std::invoke_result_t<Func, Closeable&>>
96with_closeable(Closeable&& obj, Func func)
noexcept {
97 return do_with(std::move(obj), [func = std::move(func)] (Closeable& obj)
mutable {
98 return futurize_invoke(func, obj).finally([&obj] {
104template <
typename Object>
105concept stoppable =
requires (Object o) {
106 { o.stop() } SEASTAR_DEFERRED_ACTION_NOEXCEPT -> std::same_as<future<>>;
116template <
typename Object>
117requires stoppable<Object>
119 std::reference_wrapper<Object> _obj;
120 bool _stopped =
false;
122 void do_stop()
noexcept {
125 _obj.get().stop().get();
142 _stopped = std::exchange(x._stopped,
true);
162template <stoppable Stoppable, std::invocable<Stoppable&> Func>
163requires std::is_nothrow_move_constructible_v<Stoppable> && std::is_nothrow_move_constructible_v<Func>
164inline futurize_t<std::invoke_result_t<Func, Stoppable&>>
165with_stoppable(Stoppable&& obj, Func func)
noexcept {
166 return do_with(std::move(obj), [func = std::move(func)] (Stoppable& obj)
mutable {
167 return futurize_invoke(func, obj).finally([&obj] {
Definition: closeable.hh:49
void close_now() noexcept
Close obj once now.
Definition: closeable.hh:81
deferred_close & operator=(deferred_close &&x) noexcept
Definition: closeable.hh:70
void cancel() noexcept
Definition: closeable.hh:88
deferred_close(deferred_close &&x) noexcept
Definition: closeable.hh:65
~deferred_close()
Destruct the deferred_close object and auto-close obj.
Definition: closeable.hh:77
deferred_close(Object &obj) noexcept
Definition: closeable.hh:62
Definition: closeable.hh:118
deferred_stop(Object &obj) noexcept
Definition: closeable.hh:131
void stop_now() noexcept
Stop obj once now.
Definition: closeable.hh:150
deferred_stop(deferred_stop &&x) noexcept
Definition: closeable.hh:134
~deferred_stop()
Destruct the deferred_stop object and auto-stop obj.
Definition: closeable.hh:146
void cancel() noexcept
Definition: closeable.hh:157
deferred_stop & operator=(deferred_stop &&x) noexcept
Definition: closeable.hh:139
auto do_with(T1 &&rv1, T2 &&rv2, More &&... more) noexcept
Definition: do_with.hh:135
Seastar API namespace.
Definition: abort_on_ebadf.hh:26