addHandlers(_:position:)
AsyncAwaitSupport.swift:292- iOS
- 13+
- macOS
- 10.15+
- tvOS
- 13+
- watchOS
- 6+
@preconcurrency func addHandlers(_ handlers: [any ChannelHandler & Sendable], position: ChannelPipeline.Position = .last) async throws
@preconcurrency func addHandlers(_ handlers: [any ChannelHandler & Sendable], position: ChannelPipeline.Position = .last) async throws
s7NIOCore15ChannelPipelineC11addHandlers_8positionySayAA0B7Handler_pG_AC8PositionOtYaKF
What are these?2S3D9
import NIOCore
The core abstractions that make up SwiftNIO.
final class ChannelPipeline
A list of ChannelHandler
s that handle or intercept inbound events and outbound operations of a Channel
. ChannelPipeline
implements an advanced form of the Intercepting Filter pattern to give a user full control over how an event is handled and how the ChannelHandler
s in a pipeline interact with each other.
protocol ChannelHandler : AnyObject
Base protocol for handlers that handle I/O events or intercept an I/O operation.
protocol Sendable
A thread-safe type whose values can be shared across arbitrary concurrent contexts without introducing a risk of data races. Values of the type may have no shared mutable state, or they may protect that state with a lock or by forcing it to only be accessed from a specific actor.
@preconcurrency enum Position
A Position
within the ChannelPipeline
used to insert handlers into the ChannelPipeline
.
init(channel: any Channel)
Create ChannelPipeline
for a given Channel
. This method should never be called by the end-user directly: it is only intended for use with custom Channel
implementations. Users should always use channel.pipeline
to access the ChannelPipeline
for a Channel
.
var debugDescription: String { get }
let eventLoop: any EventLoop
The EventLoop
that is used by the underlying Channel
.
var syncOperations: ChannelPipeline.SynchronousOperations { get }
Returns a view of operations which can be performed synchronously on this pipeline. All operations must be called on the event loop.
@preconcurrency func addHandler(_ handler: any ChannelHandler & Sendable, name: String? = nil, position: ChannelPipeline.Position = .last) -> EventLoopFuture<Void>
Add a ChannelHandler
to the ChannelPipeline
.
@preconcurrency func addHandler(_ handler: any ChannelHandler & Sendable, name: String? = nil, position: ChannelPipeline.Position = .last) async throws
@preconcurrency func addHandlers(_ handlers: any ChannelHandler & Sendable..., position: ChannelPipeline.Position = .last) -> EventLoopFuture<Void>
Adds the provided channel handlers to the pipeline in the order given, taking account of the behaviour of ChannelHandler.add(first:)
.
@preconcurrency func addHandlers(_ handlers: [any ChannelHandler & Sendable], position: ChannelPipeline.Position = .last) -> EventLoopFuture<Void>
Adds the provided channel handlers to the pipeline in the order given, taking account of the behaviour of ChannelHandler.add(first:)
.
@preconcurrency func addHandlers(_ handlers: any ChannelHandler & Sendable..., position: ChannelPipeline.Position = .last) async throws
func bind(to address: SocketAddress, promise: EventLoopPromise<Void>?)
func close(mode: CloseMode = .all, promise: EventLoopPromise<Void>?)
func connect(to address: SocketAddress, promise: EventLoopPromise<Void>?)
func containsHandler(name: String) -> EventLoopFuture<Void>
Returns if the ChannelHandler
of the given type is contained in the pipeline.
@preconcurrency func containsHandler<Handler>(type: Handler.Type) -> EventLoopFuture<Void> where Handler : ChannelHandler
Returns if the ChannelHandler
of the given type is contained in the pipeline.
@preconcurrency func context<Handler>(handlerType: Handler.Type) -> EventLoopFuture<ChannelHandlerContext> where Handler : ChannelHandler
Returns the ChannelHandlerContext
that belongs to a ChannelHandler
of the given type.
func context(name: String) -> EventLoopFuture<ChannelHandlerContext>
Returns the ChannelHandlerContext
that belongs to a ChannelHandler
.
func fireChannelActive()
func fireChannelInactive()
func fireChannelRead<T>(_ data: T) where T : Sendable
func fireChannelReadComplete()
func fireChannelRegistered()
func fireChannelUnregistered()
func fireChannelWritabilityChanged()
func fireErrorCaught(_ error: any Error)
@preconcurrency func fireUserInboundEventTriggered(_ event: any Sendable)
func flush()
@preconcurrency func handler<Handler>(type _: Handler.Type) -> EventLoopFuture<Handler> where Handler : ChannelHandler
Returns the first ChannelHandler
of the given type.
func inboundBufferedBytes() -> EventLoopFuture<Int>
Retrieve the total number of bytes buffered for inbound.
func outboundBufferedBytes() -> EventLoopFuture<Int>
Retrieve the total number of bytes buffered for outbound.
func read()
func register(promise: EventLoopPromise<Void>?)
@preconcurrency func removeHandler(_ handler: any RemovableChannelHandler & Sendable) -> EventLoopFuture<Void>
Remove a ChannelHandler
from the ChannelPipeline
.
@preconcurrency func removeHandler(_ handler: any RemovableChannelHandler & Sendable) async throws
@preconcurrency func removeHandler(_ handler: any RemovableChannelHandler & Sendable, promise: EventLoopPromise<Void>?)
Remove a ChannelHandler
from the ChannelPipeline
.
func removeHandler(name: String) -> EventLoopFuture<Void>
Remove a ChannelHandler
from the ChannelPipeline
.
func removeHandler(name: String) async throws
func removeHandler(name: String, promise: EventLoopPromise<Void>?)
Remove a ChannelHandler
from the ChannelPipeline
.
@preconcurrency func triggerUserOutboundEvent(_ event: any Sendable, promise: EventLoopPromise<Void>?)
func write<T>(_ data: T, promise: EventLoopPromise<Void>?) where T : Sendable
func writeAndFlush<T>(_ data: T, promise: EventLoopPromise<Void>?) where T : Sendable
struct SynchronousOperations
A view of a ChannelPipeline
which may be used to invoke synchronous operations.
@preconcurrency func context(handler: any ChannelHandler & Sendable) async throws -> ChannelHandlerContext
@preconcurrency func context(handler: any ChannelHandler & Sendable) -> EventLoopFuture<ChannelHandlerContext>
Returns the ChannelHandlerContext
that belongs to a ChannelHandler
.
@preconcurrency func context<Handler>(handlerType: Handler.Type) async throws -> ChannelHandlerContext where Handler : ChannelHandler
func context(name: String) async throws -> ChannelHandlerContext
func fireChannelRead(_ data: NIOAny)
func removeHandler(context: ChannelHandlerContext) -> EventLoopFuture<Void>
Remove a ChannelHandler
from the ChannelPipeline
.
func removeHandler(context: ChannelHandlerContext) async throws
func removeHandler(context: ChannelHandlerContext, promise: EventLoopPromise<Void>?)
Remove a ChannelHandler
from the ChannelPipeline
.
func write(_ data: NIOAny, promise: EventLoopPromise<Void>?)
func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?)