From f3cfce2f3bc7c99179f40cfe8bc7cb2a76e353d2 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Sat, 15 Jul 2023 12:04:25 +0200 Subject: [PATCH 1/2] when any Thenable --- Sources/when.swift | 6 ++++++ Tests/CorePromise/WhenTests.swift | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Sources/when.swift b/Sources/when.swift index 8f5524259..d457aa7f9 100644 --- a/Sources/when.swift +++ b/Sources/when.swift @@ -104,6 +104,12 @@ public func when(fulfilled thenables: [U]) -> Promise<[U.T]> { return _when(thenables).map(on: nil) { thenables.map{ $0.value! } } } +#if swift(>=5.7) +public func when(fulfilled thenables: [any Thenable]) -> Promise<[Any]> { + return _when(thenables.map { $0.asVoid()}).map(on: nil) { thenables.map { $0.value! } } +} +#endif + /// Wait for all promises in a set to fulfill. public func when(fulfilled promises: U...) -> Promise where U.T == Void { return _when(promises) diff --git a/Tests/CorePromise/WhenTests.swift b/Tests/CorePromise/WhenTests.swift index 3e5a555dc..d1efd74a9 100644 --- a/Tests/CorePromise/WhenTests.swift +++ b/Tests/CorePromise/WhenTests.swift @@ -37,6 +37,26 @@ class WhenTests: XCTestCase { waitForExpectations(timeout: 1, handler: nil) } + func testAnyInt() { + #if swift(>=5.7) + let e1 = expectation(description: "") + let p1 = Promise.value(1) + let g2 = Guarantee.value(2) + let p3 = Promise.value(3) + let g4 = Guarantee.value(4) + + when(fulfilled: [p1, g2, p3, g4]).done { x in + XCTAssertEqual(x[0] as? Int, 1) + XCTAssertEqual(x[1] as? Int, 2) + XCTAssertEqual(x[2] as? Int, 3) + XCTAssertEqual(x[3] as? Int, 4) + XCTAssertEqual(x.count, 4) + e1.fulfill() + }.silenceWarning() + waitForExpectations(timeout: 1, handler: nil) + #endif + } + func testDoubleTuple() { let e1 = expectation(description: "") let p1 = Promise.value(1) From 60089645b7ded3ee3e085688c291c4de3fbcfa3b Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Sat, 15 Jul 2023 12:44:38 +0200 Subject: [PATCH 2/2] Tests --- Tests/CorePromise/XCTestManifests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/CorePromise/XCTestManifests.swift b/Tests/CorePromise/XCTestManifests.swift index cb0347965..21dc7b5f3 100644 --- a/Tests/CorePromise/XCTestManifests.swift +++ b/Tests/CorePromise/XCTestManifests.swift @@ -267,6 +267,7 @@ extension WhenTests { // to regenerate. static let __allTests__WhenTests = [ ("testAllSealedRejectedFirstOneRejects", testAllSealedRejectedFirstOneRejects), + ("testAnyInt", testAnyInt), ("testDoubleTuple", testDoubleTuple), ("testDoubleTupleGuarantees", testDoubleTupleGuarantees), ("testEmpty", testEmpty),