@@ -663,6 +663,8 @@ extension ServerBootstrap {
663663 /// - serverBackPressureStrategy: The back pressure strategy used by the server socket channel.
664664 /// - childChannelInitializer: A closure to initialize the channel. The return value of this closure is used in the `onConnection`
665665 /// closure.
666+ /// - onceStartup: A closure that will be called once the server has been started. Use this to get access to
667+ /// the port number, if you used port `0` in the ``BindTarget``.
666668 /// - onConnection: A closure to handle the connection. Use the channel's `inbound` property to read from
667669 /// the connection and channel's `outbound` to write to the connection.
668670 ///
@@ -673,7 +675,8 @@ extension ServerBootstrap {
673675 target: BindTarget ,
674676 serverBackPressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies . HighLowWatermark ? = nil ,
675677 childChannelInitializer: @escaping @Sendable ( Channel ) -> EventLoopFuture < NIOAsyncChannel < Inbound , Outbound > > ,
676- _ onConnection: @escaping @Sendable (
678+ onceStartup: ( Channel ) -> ( ) = { _ in } ,
679+ onConnection: @escaping @Sendable (
677680 _ channel: NIOAsyncChannel < Inbound , Outbound >
678681 ) async -> ( )
679682 ) async throws {
@@ -683,6 +686,8 @@ extension ServerBootstrap {
683686 childChannelInitializer: childChannelInitializer
684687 )
685688
689+ onceStartup ( channel. channel)
690+
686691 try await withTaskCancellationHandler {
687692 try await channel. executeThenClose { inbound, outbound in
688693 // we need to dance the result dance here, since we can't throw from the
0 commit comments