writeAndFlush(_:)
An overload of Channel.writeAndFlush
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
func writeAndFlush<T>(_ data: T) -> EventLoopFuture<Void>
An overload of Channel.writeAndFlush
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
func writeAndFlush<T>(_ data: T) -> EventLoopFuture<Void>
s11NIOEmbedded15EmbeddedChannelC13writeAndFlushy7NIOCore15EventLoopFutureCyytGxlF
What are these?18YWW
import NIOEmbedded
final class EmbeddedChannel
EmbeddedChannel
is a Channel
implementation that does neither any actual IO nor has a proper eventing mechanism. The prime use-case for EmbeddedChannel
is in unit tests when you want to feed the inbound events and check the outbound events manually.
final class EmbeddedEventLoop
An EventLoop
that is embedded in the current running context with no external control.
final class EventLoopFuture<Value>
Holder for a result that will be provided later.
typealias Void = ()
The return type of functions that don’t explicitly specify a return type, that is, an empty tuple ()
.
convenience init(handler: ChannelHandler? = nil, loop: EmbeddedEventLoop = EmbeddedEventLoop())
Create a new instance.
init(handlers: [ChannelHandler], loop: EmbeddedEventLoop = EmbeddedEventLoop())
Create a new instance.
var _channelCore: ChannelCore { get }
var allocator: ByteBufferAllocator
var allowRemoteHalfClosure: Bool { get set }
var closeFuture: EventLoopFuture<Void> { get }
var embeddedEventLoop: EmbeddedEventLoop
Returns the EmbeddedEventLoop
that this EmbeddedChannel
uses. This will return the same instance as EmbeddedChannel.eventLoop
but as the concrete EmbeddedEventLoop
rather than as EventLoop
existential.
var eventLoop: EventLoop { get }
var isActive: Bool { get }
Returns true
if the EmbeddedChannel
is ‘active’.
var isWritable: Bool
var localAddress: SocketAddress? { get set }
let parent: Channel?
nil
because EmbeddedChannel
s don’t have parents.
var pipeline: ChannelPipeline { get }
var remoteAddress: SocketAddress? { get set }
final var syncOptions: NIOSynchronousChannelOptions? { get }
func bind(to address: SocketAddress, promise: EventLoopPromise<Void>?)
Fires the (outbound) bind
event through the ChannelPipeline
. If the event hits the EmbeddedChannel
which happens when it travels the ChannelPipeline
all the way to the front, this will also set the EmbeddedChannel
’s localAddress
.
func connect(to address: SocketAddress, promise: EventLoopPromise<Void>?)
Fires the (outbound) connect
event through the ChannelPipeline
. If the event hits the EmbeddedChannel
which happens when it travels the ChannelPipeline
all the way to the front, this will also set the EmbeddedChannel
’s remoteAddress
.
func finish() throws -> LeftOverState
Synchronously closes the EmbeddedChannel
.
func finish(acceptAlreadyClosed: Bool) throws -> LeftOverState
Synchronously closes the EmbeddedChannel
.
func getOption<Option>(_ option: Option) -> EventLoopFuture<Option.Value> where Option : ChannelOption
func readInbound<T>(as type: T.Type = T.self) throws -> T?
If available, this method reads one element of type T
out of the EmbeddedChannel
’s inbound buffer. If the first element was of a different type than requested, EmbeddedChannel.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) throws -> T?
If available, this method reads one element of type T
out of the EmbeddedChannel
’s outbound buffer. If the first element was of a different type than requested, EmbeddedChannel.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() throws
This method will throw the error that is stored in the EmbeddedChannel
if any.
func write<T>(_ data: T) -> EventLoopFuture<Void>
An overload of Channel.write
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
func write<T>(_ data: T, promise: EventLoopPromise<Void>?)
An overload of Channel.write
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
func writeAndFlush<T>(_ data: T, promise: EventLoopPromise<Void>?)
An overload of Channel.writeAndFlush
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
@discardableResult func writeInbound<T>(_ data: T) throws -> BufferState
Sends an inbound channelRead
event followed by a channelReadComplete
event through the ChannelPipeline
.
@discardableResult func writeOutbound<T>(_ data: T) throws -> BufferState
Sends an outbound writeAndFlush
event through the ChannelPipeline
.
enum BufferState
BufferState
represents the state of either the inbound, or the outbound EmbeddedChannel
buffer. These buffers contain data that travelled the ChannelPipeline
all the way.
enum LeftOverState
LeftOverState
represents any left-over inbound, outbound, and pending outbound events that hit the EmbeddedChannel
and were not consumed when finish
was called on the EmbeddedChannel
.
struct SynchronousOptions
struct WrongTypeError
WrongTypeError
is throws if you use readInbound
or readOutbound
and request a certain type but the first item in the respective buffer is of a different type.