mirror of
https://github.com/apple/swift-nio
synced 2026-11-27 05:04:22 +00:00
Motivation: A somewhat common requirement when working with chains of futures is needing to hop from one event loop to another. This is particularly common when relying on the fact that EventLoopFuture will synchronize with the event loop that created it: you often want to rely on that implicit locking, rather than use Dispatch or Lock to achieve the same effect. While doing this hop requires relatively little code, it's not necessarily totally apparent to new users how they would do it. Additionally, the most naive implementation incurs the overhead of allocations and reference counting in cases where it's not necessary (e.g. when you have only one event loop, or when both work items are being scheduled on the same event loop). For this reason, we should have a nice concise way for a user to request this behaviour and get a relatively performant implementation of the behaviour. Modifications: Added EventLoopFuture<T>.on(eventLoop:). Changed AcceptHandler to use the new method rather than its (slower) alternative. Result: Users will have an easier time working with EventLoopFutures.