parent
nil
because NIOAsyncTestingChannel
s don’t have parents.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
let parent: Channel?
nil
because NIOAsyncTestingChannel
s don’t have parents.
let parent: Channel?
s11NIOEmbedded22NIOAsyncTestingChannelC6parent7NIOCore0D0_pSgvp
What are these?48PRR
import NIOEmbedded
final class NIOAsyncTestingChannel
A Channel
with fine-grained control for testing.
protocol Channel : AnyObject, ChannelOutboundInvoker, _NIOPreconcurrencySendable
A Channel
is easiest thought of as a network socket. But it can be anything that is capable of I/O operations such as read, write, connect, and bind.
@preconcurrency convenience init(handler: ChannelHandler & Sendable, loop: NIOAsyncTestingEventLoop = NIOAsyncTestingEventLoop()) async
Create a new instance.
@preconcurrency convenience init(handlers: [ChannelHandler & Sendable], loop: NIOAsyncTestingEventLoop = NIOAsyncTestingEventLoop()) async
Create a new instance.
init(loop: NIOAsyncTestingEventLoop = NIOAsyncTestingEventLoop())
Create a new instance.
convenience init(loop: NIOAsyncTestingEventLoop = NIOAsyncTestingEventLoop(), channelInitializer: @escaping (NIOAsyncTestingChannel) throws -> Void) async throws
Create a new instance.
var _channelCore: ChannelCore { get }
let allocator: ByteBufferAllocator
var allowRemoteHalfClosure: Bool { get set }
var closeFuture: EventLoopFuture<Void> { get }
var eventLoop: EventLoop { get }
var isActive: Bool { get }
Returns true
if the NIOAsyncTestingChannel
is ‘active’.
var isWritable: Bool { get set }
var localAddress: SocketAddress? { get set }
var pipeline: ChannelPipeline { get }
var remoteAddress: SocketAddress? { get set }
final var syncOptions: NIOSynchronousChannelOptions? { get }
let testingEventLoop: NIOAsyncTestingEventLoop
Returns the NIOAsyncTestingEventLoop
that this NIOAsyncTestingChannel
uses. This will return the same instance as eventLoop
but as the concrete NIOAsyncTestingEventLoop
rather than as EventLoop
existential.
func bind(to address: SocketAddress, promise: EventLoopPromise<Void>?)
Fires the (outbound) bind
event through the ChannelPipeline
. If the event hits the NIOAsyncTestingChannel
which happens when it travels the ChannelPipeline
all the way to the front, this will also set the NIOAsyncTestingChannel
’s localAddress
.
func connect(to address: SocketAddress, promise: EventLoopPromise<Void>?)
Fires the (outbound) connect
event through the ChannelPipeline
. If the event hits the NIOAsyncTestingChannel
which happens when it travels the ChannelPipeline
all the way to the front, this will also set the NIOAsyncTestingChannel
’s remoteAddress
.
func finish() async throws -> LeftOverState
Asynchronously closes the NIOAsyncTestingChannel
.
func finish(acceptAlreadyClosed: Bool) async throws -> LeftOverState
Asynchronously closes the NIOAsyncTestingChannel
.
func getOption<Option>(_ option: Option) -> EventLoopFuture<Option.Value> where Option : ChannelOption
func readInbound<T>(as type: T.Type = T.self) async throws -> T? where T : Sendable
If available, this method reads one element of type T
out of the NIOAsyncTestingChannel
’s inbound buffer. If the first element was of a different type than requested, WrongTypeError
will be thrown, if there are no elements in the outbound buffer, nil
will be returned.
func readOutbound<T>(as type: T.Type = T.self) async throws -> T? where T : Sendable
If available, this method reads one element of type T
out of the NIOAsyncTestingChannel
’s outbound buffer. If the first element was of a different type than requested, WrongTypeError
will be thrown, if there are no elements in the outbound buffer, nil
will be returned.
func setOption<Option>(_ option: Option, value: Option.Value) -> EventLoopFuture<Void> where Option : ChannelOption
func throwIfErrorCaught() async throws
This method will throw the error that is stored in the NIOAsyncTestingChannel
if any.
func waitForInboundWrite<T>(as type: T.Type = T.self) async throws -> T where T : Sendable
This method is similar to readInbound(as:)
but will wait if the inbound buffer is empty. If available, this method reads one element of type T
out of the NIOAsyncTestingChannel
’s inbound buffer. If the first element was of a different type than requested, WrongTypeError
will be thrown, if there are no elements in the outbound buffer, this method will wait until an element is in the inbound buffer.
func waitForOutboundWrite<T>(as type: T.Type = T.self) async throws -> T where T : Sendable
This method is similar to readOutbound(as:)
but will wait if the outbound buffer is empty. If available, this method reads one element of type T
out of the NIOAsyncTestingChannel
’s outbound buffer. If the first element was of a different type than requested, WrongTypeError
will be thrown, if there are no elements in the outbound buffer, nil
will be returned.
@discardableResult func writeInbound<T>(_ data: T) async throws -> BufferState where T : Sendable
Sends an inbound channelRead
event followed by a channelReadComplete
event through the ChannelPipeline
.
@discardableResult func writeOutbound<T>(_ data: T) async throws -> BufferState where T : Sendable
Sends an outbound writeAndFlush
event through the ChannelPipeline
.
enum BufferState
BufferState
represents the state of either the inbound, or the outbound NIOAsyncTestingChannel
buffer.
enum LeftOverState
LeftOverState
represents any left-over inbound, outbound, and pending outbound events that hit the NIOAsyncTestingChannel
and were not consumed when finish
was called on the NIOAsyncTestingChannel
.
struct SynchronousOptions
struct WrongTypeError
WrongTypeError
is thrown if you use readInbound(as:)
or readOutbound(as:)
and request a certain type but the first item in the respective buffer is of a different type.