From 6776bd71a7dc9657c58f7270e3525717d5174b25 Mon Sep 17 00:00:00 2001 From: Brian Olsen Date: Mon, 11 Aug 2025 19:01:52 +0200 Subject: [PATCH] capnp-rpc: Add disconnect_background to Disconnector This adds a public disconnect_background function to Disconnector so that you can signal it to disconnect but not have to wait for it to do so. --- capnp-rpc/src/rpc.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/capnp-rpc/src/rpc.rs b/capnp-rpc/src/rpc.rs index 47a48869e..507c7ebed 100644 --- a/capnp-rpc/src/rpc.rs +++ b/capnp-rpc/src/rpc.rs @@ -1637,15 +1637,13 @@ impl Disconnector { )); } } -} - -impl Future for Disconnector -where - VatId: 'static, -{ - type Output = Result<(), capnp::Error>; - fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll { + /// Disconnects the `RpcSystem`'s ConnectionState but doesn't wait for it to close. + /// + /// This is useful if you want to just signal to the `RpcSystem` that you are done + /// with eg. a client connection and would like for it to shutdown but you either + /// don't want to or can't wait for it to complete the shutdown. + pub fn disconnect_background(&mut self) { self.state = match self.state { DisconnectorState::New => { self.disconnect(); @@ -1660,6 +1658,17 @@ where } DisconnectorState::Disconnected => DisconnectorState::Disconnected, }; + } +} + +impl Future for Disconnector +where + VatId: 'static, +{ + type Output = Result<(), capnp::Error>; + + fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll { + self.disconnect_background(); match self.state { DisconnectorState::New => unreachable!(), DisconnectorState::Disconnecting => {