]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/async: yield_waiter can return the associated executor
authorCasey Bodley <cbodley@redhat.com>
Tue, 25 Mar 2025 22:06:36 +0000 (18:06 -0400)
committerMarcel Lauhoff <marcel.lauhoff@clyso.com>
Mon, 1 Jun 2026 16:43:28 +0000 (18:43 +0200)
also adds an empty() function so it's easier to specify its precondition

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/common/async/yield_waiter.h

index 6ace1f2efc467692aae3a3455d57a695f8cca5d0..60c2e613aee8b513ba3ecd4346c935e2b2935c62 100644 (file)
@@ -20,6 +20,7 @@
 #include <optional>
 #include <boost/asio/append.hpp>
 #include <boost/asio/associated_cancellation_slot.hpp>
+#include <boost/asio/associated_executor.hpp>
 #include <boost/asio/async_result.hpp>
 #include <boost/asio/dispatch.hpp>
 #include <boost/asio/spawn.hpp>
@@ -65,6 +66,18 @@ class yield_waiter {
   /// Returns true if there's a handler awaiting completion.
   operator bool() const { return state.has_value(); }
 
+  /// Returns false if there's a handler awaiting completion.
+  bool empty() const { return !state.has_value(); }
+
+  /// Returns the captured completion handler's executor.
+  /// Precondition: !empty()
+  using executor_type = boost::asio::any_io_executor;
+  executor_type get_executor() const
+  {
+    return boost::asio::get_associated_executor(
+        state->handler, state->work.get_executor());
+  }
+
   /// Suspends the given yield_context until the captured handler is invoked
   /// via complete() or cancel().
   template <typename CompletionToken>
@@ -167,6 +180,18 @@ class yield_waiter<void> {
   /// Returns true if there's a handler awaiting completion.
   operator bool() const { return state.has_value(); }
 
+  /// Returns false if there's a handler awaiting completion.
+  bool empty() const { return !state.has_value(); }
+
+  /// Returns the captured completion handler's executor.
+  /// Precondition: !empty()
+  using executor_type = boost::asio::any_io_executor;
+  executor_type get_executor() const
+  {
+    return boost::asio::get_associated_executor(
+        state->handler, state->work.get_executor());
+  }
+
   /// Suspends the given yield_context until the captured handler is invoked
   /// via complete() or cancel().
   template <typename CompletionToken>