1414
1515import Dispatch
1616import Foundation
17+ import NIOCore
1718@testable import SotoCore
1819import XCTest
1920
20- extension EventLoopFuture {
21- /// When EventLoopFuture has any result the callback is called with the Result. The callback returns an EventLoopFuture<>
22- /// which should be completed before result is passed on
23- func flatAlways< NewValue> ( file: StaticString = #file, line: UInt = #line, _ callback: @escaping ( Result < Value , Error > ) -> EventLoopFuture < NewValue > ) -> EventLoopFuture < NewValue > {
24- let next = eventLoop. makePromise ( of: NewValue . self)
25- self . whenComplete { result in
26- switch result {
27- case . success:
28- callback ( result) . cascade ( to: next)
29- case . failure( let error) :
30- _ = callback ( result) . always { _ in next. fail ( error) }
31- }
32- }
33- return next. futureResult
34- }
35- }
36-
37- @available ( * , noasync, message: " runAndWait() can block indefinitely " )
21+ @available ( * , noasync, message: " runThrowingTask() can block indefinitely " )
3822func runThrowingTask< T> ( on eventLoop: EventLoop , _ task: @escaping @Sendable ( ) async throws -> T ) throws -> T {
3923 let promise = eventLoop. makePromise ( of: T . self)
4024 Task {
@@ -48,7 +32,7 @@ func runThrowingTask<T>(on eventLoop: EventLoop, _ task: @escaping @Sendable ()
4832 return try promise. futureResult. wait ( )
4933}
5034
51- @available ( * , noasync, message: " runAndWait () can block indefinitely" )
35+ @available ( * , noasync, message: " runTask () can block indefinitely" )
5236func runTask< T> ( on eventLoop: EventLoop , _ task: @escaping @Sendable ( ) async -> T ) -> T {
5337 let promise = eventLoop. makePromise ( of: T . self)
5438 Task {
0 commit comments