Is this async method cancellation-safe?

⚓ Rust    📅 2025-07-11    👤 surdeus    👁️ 3      

surdeus

I'm writing an IRC client library, and, in order to generalize handling of things like PINGs and CTCP messages, I've implemented a sans-IO "autoresponder" trait that can be attached to a client to make it automatically respond to select incoming messages whenever the "receive" method is called. In its simplest form, the receive method is intended to operate as follows:

  • Async: Receive message from server, propagating errors
  • Pass the message to the autoresponders and collect any responses they return.
  • Async: Send autoresponses back to the server, propagating errors
  • If the message was not marked "handled" by any autoresponders, return it. Otherwise, discard it and loop back to the start of the method.

Now, this method needs to handle being cancelled by a timeout or other mechanism, ideally by not losing any data and resuming any unfinished operations on the next call. By storing data on the client, I believe I've achieved cancellation safety, but I'd like someone else to check.

Links to the method and select associated code:

Any other code critiques are appreciated.

1 post - 1 participant

Read full topic

🏷️ rust_feed