-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Async Await support to NIOTSListenerBootstrap childChannelInitializer #134
Comments
Yeah, this is something we want to do, but thus far haven't got around to it. In the meantime, you can use this: extension NIOTSListenerBootstrap {
public func serverChannelInitializer(_ initializer: @escaping @Sendable (Channel) async throws -> Void) -> Self {
return self.serverChannelInitializer { channel in
let promise = channel.eventLoop.makePromise(of: Void.self)
promise.completeWithTask {
await initializer(channel)
}
return promise.futureResult
}
}
public func childChannelInitializer(_ initializer: @escaping @Sendable (Channel) async throws -> Void) -> Self {
return self.childChannelInitializer { channel in
let promise = channel.eventLoop.makePromise(of: Void.self)
promise.completeWithTask {
await initializer(channel)
}
return promise.futureResult
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
When using
NIOTSListenerBootstrap
I would expect to be able to provide an async block since the common methods one would call within this have await-able versions. egchannel.pipeline.addHandler
.SwiftNIO version/commit hash
Swift & OS version (output of
swift --version && uname -a
)P.S maybe there is an easy way to create an async task connected to the event loop that returns a
EventLoopFuture<Void>
but I cant find such a method on thechannel.eventloop
(more of an issue for SwiftNIO repo through)The text was updated successfully, but these errors were encountered: