capnproto-rust icon indicating copy to clipboard operation
capnproto-rust copied to clipboard

capnp-rpc: Add disconnect_background to Disconnector

Open griff opened this issue 4 months ago • 1 comments

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.

I usually run the RpcSystem with spawn_local and would like to be able to just signal that it should shut down in like a Drop implementation for my Client.

It would also make my graceful shutdown listener for the server slightly less clunky since that needs to do this:

if this.cancelled_guard.is_some() {
    match (
        this.rpc_system.as_mut().poll(cx)?,
        this.disconnector.as_mut().poll(cx)?,
    ) {
        (task::Poll::Ready(_), task::Poll::Ready(_)) => task::Poll::Ready(Ok(())),
        _ => task::Poll::Pending,
    }
} else {
    this.rpc_system.poll(cx)
}

While with this PR it would look like this:

if this.cancelled_guard.is_some() {
    this.disconnector.disconnect_background();
}
this.rpc_system.poll(cx)

griff avatar Aug 11 '25 17:08 griff

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 50.65%. Comparing base (ab342b3) to head (6776bd7). :warning: Report is 188 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #581      +/-   ##
==========================================
- Coverage   51.64%   50.65%   -1.00%     
==========================================
  Files          69       70       +1     
  Lines       33735    32295    -1440     
==========================================
- Hits        17422    16358    -1064     
+ Misses      16313    15937     -376     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Aug 11 '25 17:08 codecov[bot]