fgerlits commented on code in PR #2254:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2254#discussion_r3970297181


##########
extension-framework/include/utils/net/Server.h:
##########
@@ -67,9 +75,21 @@ class Server {
   Server(std::optional<size_t> max_queue_size, uint16_t port, 
std::shared_ptr<core::logging::Logger> logger)
       : port_(port), max_queue_size_(max_queue_size), 
logger_(std::move(logger)) {}
 
+  // Spawn a coroutine on io_context_ with a cancellation slot so stop() can 
end it and let the context drain
+  // gracefully. Must be called from the io_context thread (i.e. from run() 
before io_context_.run(), or from within
+  // a coroutine running on it); cancellation_signals_ is only ever touched on 
that thread, so it needs no locking.
+  template<typename T>
+  void asyncSpawn(asio::awaitable<T> coroutine) {
+    const auto cancellation_signal_it = 
cancellation_signals_.emplace(cancellation_signals_.end());
+    asio::co_spawn(io_context_, std::move(coroutine),
+        asio::bind_cancellation_slot(cancellation_signal_it->slot(),
+            [this, cancellation_signal_it](std::exception_ptr, auto&&...) { 
cancellation_signals_.erase(cancellation_signal_it); }));
+  }

Review Comment:
   Exceptions were also swallowed silently before this PR; I have added a 
comment about this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to