mirror of
https://github.com/apple/swift-nio-extras
synced 2026-11-24 04:37:58 +00:00
Motivation: `RequestResponseHandler` and `RequestResponseWithIDHandler` previously allowed non-`Sendable` Requests to move across event loops by wrapping it in `UnsafeTransfer`, which disabled the compiler's sendability checking. Requiring every Response to be `Sendable` would solve the safety issue but it limits how the handlers can be used. Modifications: * Extracted the common logic of both handlers into a single state machine. * Modified the original implementations to have Request conform to `Sendable` * Introduced two new variants that don't care if the Request is `Sendable` as promises moving to different event loops would be failed with an error. * Removed the UnsafeTransfer type as it is not used anymore. * Added unit tests to confirm that the Sendable variants allow for promises for different event loops and non-Sendable variants fail the promises with an Error. Result: * Compiler's sendability checks are restored for the handlers. --------- Co-authored-by: George Barnett <gbarnett@apple.com>