mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
Motivation: We added synchronous pipeline operations to allow the caller to save allocations when they know they are already on the correct event loop. However, we missed a trick! In some cases the caller cannot guarantee they are on the correct event loop and must use an asynchronous method instead. If that method returns a void future and is called on the event loop, then we can perform the operation synchronously and return a cached void future. Modifications: - Add API to `EventLoop` for creating a 'completed' future with a `Result` (similar to `EventLoopPromise.completeWith`) - Add an equivalent for making completed void futures - Use these when asynchronously adding handlers and the caller is already on the right event loop. Result: - Fewer allocations on the happiest of happy paths when adding handlers asynchronously to a pipeline.