@@ -121,12 +121,8 @@ public func withThrowingTimeout<T>(
121121 body: ( ) async throws -> T
122122) async throws -> T {
123123 let transferringBody = { try await Transferring ( body ( ) ) }
124- typealias NonSendableClosure = ( ) async throws -> Transferring < T >
125- typealias SendableClosure = @Sendable ( ) async throws -> Transferring < T >
126124 return try await withoutActuallyEscaping ( transferringBody) {
127- ( _ fn: @escaping NonSendableClosure ) async throws -> Transferring < T > in
128- let sendableFn = unsafeBitCast ( fn, to: SendableClosure . self)
129- return try await _withThrowingTimeout ( body: sendableFn) {
125+ try await _withThrowingTimeout ( body: $0) {
130126 try await Task . sleep ( nanoseconds: UInt64 ( seconds * 1_000_000_000 ) )
131127 throw TimeoutError ( " Task timed out before completion. Timeout: \( seconds) seconds. " )
132128 }
@@ -140,12 +136,8 @@ public func withThrowingTimeout<T>(
140136 body: ( ) async throws -> T
141137) async throws -> T {
142138 let transferringBody = { try await Transferring ( body ( ) ) }
143- typealias NonSendableClosure = ( ) async throws -> Transferring < T >
144- typealias SendableClosure = @Sendable ( ) async throws -> Transferring < T >
145139 return try await withoutActuallyEscaping ( transferringBody) {
146- ( _ fn: @escaping NonSendableClosure ) async throws -> Transferring < T > in
147- let sendableFn = unsafeBitCast ( fn, to: SendableClosure . self)
148- return try await _withThrowingTimeout ( body: sendableFn) {
140+ try await _withThrowingTimeout ( body: $0) {
149141 try await Task . sleep ( until: instant, tolerance: tolerance, clock: ContinuousClock ( ) )
150142 throw TimeoutError ( " Task timed out before completion. Deadline: \( instant) . " )
151143 }
@@ -154,12 +146,13 @@ public func withThrowingTimeout<T>(
154146
155147// Sendable
156148private func _withThrowingTimeout< T: Sendable > (
157- body: @Sendable @ escaping ( ) async throws -> T ,
149+ body: @escaping ( ) async throws -> T ,
158150 timeout: @Sendable @escaping ( ) async throws -> Never
159151) async throws -> T {
160- try await withThrowingTaskGroup ( of: T . self) { group in
152+ let body = Transferring ( body)
153+ return try await withThrowingTaskGroup ( of: T . self) { group in
161154 group. addTask {
162- try await body ( )
155+ try await body. value ( )
163156 }
164157 group. addTask {
165158 try await timeout ( )
0 commit comments