File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -104,6 +104,12 @@ public func when<U: Thenable>(fulfilled thenables: [U]) -> Promise<[U.T]> {
104104 return _when ( thenables) . map ( on: nil ) { thenables. map { $0. value! } }
105105}
106106
107+ #if swift(>=5.7)
108+ public func when( fulfilled thenables: [ any Thenable ] ) -> Promise < [ Any ] > {
109+ return _when ( thenables. map { $0. asVoid ( ) } ) . map ( on: nil ) { thenables. map { $0. value! } }
110+ }
111+ #endif
112+
107113/// Wait for all promises in a set to fulfill.
108114public func when< U: Thenable > ( fulfilled promises: U ... ) -> Promise < Void > where U. T == Void {
109115 return _when ( promises)
Original file line number Diff line number Diff line change @@ -37,6 +37,26 @@ class WhenTests: XCTestCase {
3737 waitForExpectations ( timeout: 1 , handler: nil )
3838 }
3939
40+ func testAnyInt( ) {
41+ #if swift(>=5.7)
42+ let e1 = expectation ( description: " " )
43+ let p1 = Promise . value ( 1 )
44+ let g2 = Guarantee . value ( 2 )
45+ let p3 = Promise . value ( 3 )
46+ let g4 = Guarantee . value ( 4 )
47+
48+ when ( fulfilled: [ p1, g2, p3, g4] ) . done { x in
49+ XCTAssertEqual ( x [ 0 ] as? Int , 1 )
50+ XCTAssertEqual ( x [ 1 ] as? Int , 2 )
51+ XCTAssertEqual ( x [ 2 ] as? Int , 3 )
52+ XCTAssertEqual ( x [ 3 ] as? Int , 4 )
53+ XCTAssertEqual ( x. count, 4 )
54+ e1. fulfill ( )
55+ } . silenceWarning ( )
56+ waitForExpectations ( timeout: 1 , handler: nil )
57+ #endif
58+ }
59+
4060 func testDoubleTuple( ) {
4161 let e1 = expectation ( description: " " )
4262 let p1 = Promise . value ( 1 )
You can’t perform that action at this time.
0 commit comments