mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
Motivation: `ChannelPipeline` is explicitly thread-safe, any of the operations may be called from outside of the channel's event loop. However, there are often cases where it is known that the caller be on the right event loop, and an asynchronous API is unnecessary. In some cases -- such as when a pipeline is configured dynamically and handlers are added from the 'channelRead' implementation of one handler -- it forces the caller to write code that they might not actually need: such as buffering events which may happen before the future completes. This is unnecessary complexity when the caller knows that they must already be on an event loop. Modifications: - Add a 'SynchronousOperations' view to the 'ChannelPipeline' which is available to callers via 'syncOperations'. - Supported operations include: adding a handler, adding multiple handlers, retrieving a context via various predicates and retrieving a handler of a given type. - Some of the operations in 'ChannelPipeline' were refactored to have an explicitly synchronous version, asynchronous versions complete their promise based on the result of these calls. - Various minor documentation fixes and addition of 'self' where it was not used explicitly. Result: Users can perform synchronous operations on the 'ChannelPipeline' if they know they are on the right event loop.