mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
Add Channel extension which allows to automatically wrap data into NIOAny
This commit is contained in:
1 parent
e70587308a
commit
5705ce104a
2 files changed
+35
No files matched your search
@@ -152,6 +152,40 @@ extension Channel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Provides special extension to make writing data to the `Channel` easier by removing the need to wrap data in `NIOAny` manually.
|
||||
public extension Channel {
|
||||
|
||||
/// Write data into the `Channel`, automatically wrapping with `NIOAny`.
|
||||
///
|
||||
/// - seealso: `ChannelOutboundInvoker.write`.
|
||||
public func write<T>(_ any: T) -> EventLoopFuture<Void> {
|
||||
return self.write(data: NIOAny(any))
|
||||
}
|
||||
|
||||
/// Write data into the `Channel`, automatically wrapping with `NIOAny`.
|
||||
///
|
||||
/// - seealso: `ChannelOutboundInvoker.write`.
|
||||
public func write<T>(_ any: T, promise: EventLoopPromise<Void>?) {
|
||||
self.write(data: NIOAny(any), promise: promise)
|
||||
}
|
||||
|
||||
/// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`.
|
||||
///
|
||||
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
|
||||
public func writeAndFlush<T>(_ any: T) -> EventLoopFuture<Void> {
|
||||
return self.writeAndFlush(data: NIOAny(any))
|
||||
}
|
||||
|
||||
|
||||
/// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`.
|
||||
///
|
||||
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
|
||||
public func writeAndFlush<T>(_ any: T, promise: EventLoopPromise<Void>?) {
|
||||
self.writeAndFlush(data: NIOAny(any), promise: promise)
|
||||
}
|
||||
}
|
||||
|
||||
/// An error that can occur on `Channel` operations.
|
||||
public enum ChannelError: Error {
|
||||
/// Tried to connect on a `Channel` that is already connecting.
|
||||
|
||||
@@ -68,6 +68,7 @@ public struct NIOAny {
|
||||
case let value as AddressedEnvelope<ByteBuffer>:
|
||||
self = .bufferEnvelope(value)
|
||||
default:
|
||||
assert(!(value is NIOAny))
|
||||
self = .other(value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user