diff --git a/Sources/when.swift b/Sources/when.swift index 2f3d2ce24..88d4b1fbf 100644 --- a/Sources/when.swift +++ b/Sources/when.swift @@ -400,3 +400,18 @@ public func when(guarantees: [Guarantee]) -> Guarantee { public func when(guarantees gu: Guarantee, _ gv: Guarantee) -> Guarantee<(U, V)> { return __when([gu.asVoid(), gv.asVoid()]).map(on: nil) { (gu.value!, gv.value!) } } + +/// Waits on all provided Guarantees. +public func when(guarantees gu: Guarantee, _ gv: Guarantee, _ gw: Guarantee) -> Guarantee<(U, V, W)> { + return __when([gu.asVoid(), gv.asVoid(), gw.asVoid()]).map(on: nil) { (gu.value!, gv.value!, gw.value!) } +} + +/// Waits on all provided Guarantees. +public func when(guarantees gu: Guarantee, _ gv: Guarantee, _ gw: Guarantee, _ gx: Guarantee) -> Guarantee<(U, V, W, X)> { + return __when([gu.asVoid(), gv.asVoid(), gw.asVoid(), gx.asVoid()]).map(on: nil) { (gu.value!, gv.value!, gw.value!, gx.value!) } +} + +/// Waits on all provided Guarantees. +public func when(guarantees gu: Guarantee, _ gv: Guarantee, _ gw: Guarantee, _ gx: Guarantee, _ gy: Guarantee) -> Guarantee<(U, V, W, X, Y)> { + return __when([gu.asVoid(), gv.asVoid(), gw.asVoid(), gx.asVoid(), gy.asVoid()]).map(on: nil) { (gu.value!, gv.value!, gw.value!, gx.value!, gy.value!) } +} diff --git a/Tests/CorePromise/WhenTests.swift b/Tests/CorePromise/WhenTests.swift index e520d0ea8..46e27eb65 100644 --- a/Tests/CorePromise/WhenTests.swift +++ b/Tests/CorePromise/WhenTests.swift @@ -137,10 +137,10 @@ class WhenTests: XCTestCase { let progress = Progress(totalUnitCount: 1) progress.becomeCurrent(withPendingUnitCount: 1) - when(fulfilled: p1, p2, p3, p4).done { _ in + when(guarantees: p1, p2, p3, p4).done { _ in XCTAssertEqual(progress.completedUnitCount, 1) ex.fulfill() - }.silenceWarning() + } progress.resignCurrent() @@ -276,4 +276,52 @@ class WhenTests: XCTestCase { } waitForExpectations(timeout: 1, handler: nil) } + + func testTripleTupleGuarantees() { + let e1 = expectation(description: "") + let g1 = Guarantee.value(1) + let g2 = Guarantee.value("abc") + let g3 = Guarantee.value( 1.0) + when(guarantees: g1, g2, g3).done { u, v, w in + XCTAssertEqual(1, u) + XCTAssertEqual("abc", v) + XCTAssertEqual(1.0, w) + e1.fulfill() + } + waitForExpectations(timeout: 1, handler: nil) + } + + func testQuadrupleTupleGuarantees() { + let e1 = expectation(description: "") + let g1 = Guarantee.value(1) + let g2 = Guarantee.value("abc") + let g3 = Guarantee.value(1.0) + let g4 = Guarantee.value(true) + when(guarantees: g1, g2, g3, g4).done { u, v, w, x in + XCTAssertEqual(1, u) + XCTAssertEqual("abc", v) + XCTAssertEqual(1.0, w) + XCTAssertEqual(true, x) + e1.fulfill() + } + waitForExpectations(timeout: 1, handler: nil) + } + + func testQuintupleTupleGuarantees() { + let e1 = expectation(description: "") + let g1 = Guarantee.value(1) + let g2 = Guarantee.value("abc") + let g3 = Guarantee.value(1.0) + let g4 = Guarantee.value(true) + let g5 = Guarantee.value("a" as Character) + when(guarantees: g1, g2, g3, g4, g5).done { u, v, w, x, y in + XCTAssertEqual(1, u) + XCTAssertEqual("abc", v) + XCTAssertEqual(1.0, w) + XCTAssertEqual(true, x) + XCTAssertEqual("a" as Character, y) + e1.fulfill() + } + waitForExpectations(timeout: 1, handler: nil) + } } diff --git a/Tests/CorePromise/XCTestManifests.swift b/Tests/CorePromise/XCTestManifests.swift index 59714f748..4cd4eadb9 100644 --- a/Tests/CorePromise/XCTestManifests.swift +++ b/Tests/CorePromise/XCTestManifests.swift @@ -261,9 +261,12 @@ extension WhenTests { ("testProgress", testProgress), ("testProgressDoesNotExceed100Percent", testProgressDoesNotExceed100Percent), ("testQuadrupleTuple", testQuadrupleTuple), + ("testQuadrupleTupleGuarantees", testQuadrupleTupleGuarantees), ("testQuintupleTuple", testQuintupleTuple), + ("testQuintupleTupleGuarantees", testQuintupleTupleGuarantees), ("testRejected", testRejected), ("testTripleTuple", testTripleTuple), + ("testTripleTupleGuarantees", testTripleTupleGuarantees), ("testUnhandledErrorHandlerDoesNotFire", testUnhandledErrorHandlerDoesNotFire), ("testUnhandledErrorHandlerDoesNotFireForStragglers", testUnhandledErrorHandlerDoesNotFireForStragglers), ("testVoid", testVoid),