@@ -87,7 +87,7 @@ public protocol ConnectionRequestProtocol: Sendable {
8787
8888 /// A function that is called with a connection or a
8989 /// `PoolError`.
90- func complete( with: Result < Connection , ConnectionPoolError > )
90+ func complete( with: Result < ConnectionLease < Connection > , ConnectionPoolError > )
9191}
9292
9393@available ( macOS 13 . 0 , iOS 16 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * )
@@ -275,6 +275,7 @@ where
275275 }
276276 }
277277
278+ @inlinable
278279 public func run( ) async {
279280 await withTaskCancellationHandler {
280281 if #available( macOS 14 . 0 , iOS 17 . 0 , tvOS 17 . 0 , watchOS 10 . 0 , * ) {
@@ -319,13 +320,15 @@ where
319320 }
320321
321322 @available ( macOS 14 . 0 , iOS 17 . 0 , tvOS 17 . 0 , watchOS 10 . 0 , * )
322- private func run( in taskGroup: inout DiscardingTaskGroup ) async {
323+ @inlinable
324+ /* private */ func run( in taskGroup: inout DiscardingTaskGroup ) async {
323325 for await event in self . eventStream {
324326 self . runEvent ( event, in: & taskGroup)
325327 }
326328 }
327329
328- private func run( in taskGroup: inout TaskGroup < Void > ) async {
330+ @inlinable
331+ /* private */ func run( in taskGroup: inout TaskGroup < Void > ) async {
329332 var running = 0
330333 for await event in self . eventStream {
331334 running += 1
@@ -338,7 +341,8 @@ where
338341 }
339342 }
340343
341- private func runEvent( _ event: NewPoolActions , in taskGroup: inout some TaskGroupProtocol ) {
344+ @inlinable
345+ /* private */ func runEvent( _ event: NewPoolActions , in taskGroup: inout some TaskGroupProtocol ) {
342346 switch event {
343347 case . makeConnection( let request) :
344348 self . makeConnection ( for: request, in: & taskGroup)
@@ -405,8 +409,11 @@ where
405409 /*private*/ func runRequestAction( _ action: StateMachine . RequestAction ) {
406410 switch action {
407411 case . leaseConnection( let requests, let connection) :
412+ let lease = ConnectionLease ( connection: connection) { connection in
413+ self . releaseConnection ( connection)
414+ }
408415 for request in requests {
409- request. complete ( with: . success( connection ) )
416+ request. complete ( with: . success( lease ) )
410417 }
411418
412419 case . failRequest( let request, let error) :
@@ -430,7 +437,7 @@ where
430437 self . connectionEstablished ( bundle)
431438
432439 // after the connection has been established, we keep the task open. This ensures
433- // that the pools run method cannot be exited before all connections have been
440+ // that the pools run method can not be exited before all connections have been
434441 // closed.
435442 await withCheckedContinuation { ( continuation: CheckedContinuation < Void , Never > ) in
436443 bundle. connection. onClose {
@@ -458,7 +465,7 @@ where
458465 }
459466
460467 @inlinable
461- /*private*/ func connectionEstablishFailed( _ error: any Error , for request: StateMachine . ConnectionRequest ) {
468+ /*private*/ func connectionEstablishFailed( _ error: Error , for request: StateMachine . ConnectionRequest ) {
462469 self . observabilityDelegate. connectFailed ( id: request. connectionID, error: error)
463470
464471 self . modifyStateAndRunActions { state in
@@ -586,7 +593,6 @@ extension DiscardingTaskGroup: TaskGroupProtocol {
586593 }
587594}
588595
589- @available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * )
590596extension TaskGroup < Void > : TaskGroupProtocol {
591597 @inlinable
592598 mutating func addTask_( operation: @escaping @Sendable ( ) async -> Void ) {
0 commit comments