Skip to content

Commit

Permalink
Merge pull request #1304 from RomanPodymov/v6
Browse files Browse the repository at this point in the history
More when(guarantees:)
  • Loading branch information
mxcl authored Jan 24, 2023
2 parents cea8fb6 + 2d77dc2 commit 7fb8a92
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Sources/when.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,18 @@ public func when(guarantees: [Guarantee<Void>]) -> Guarantee<Void> {
public func when<U, V>(guarantees gu: Guarantee<U>, _ gv: Guarantee<V>) -> Guarantee<(U, V)> {
return __when([gu.asVoid(), gv.asVoid()]).map(on: nil) { (gu.value!, gv.value!) }
}

/// Waits on all provided Guarantees.
public func when<U, V, W>(guarantees gu: Guarantee<U>, _ gv: Guarantee<V>, _ gw: Guarantee<W>) -> 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<U, V, W, X>(guarantees gu: Guarantee<U>, _ gv: Guarantee<V>, _ gw: Guarantee<W>, _ gx: Guarantee<X>) -> 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<U, V, W, X, Y>(guarantees gu: Guarantee<U>, _ gv: Guarantee<V>, _ gw: Guarantee<W>, _ gx: Guarantee<X>, _ gy: Guarantee<Y>) -> 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!) }
}
52 changes: 50 additions & 2 deletions Tests/CorePromise/WhenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}
}
3 changes: 3 additions & 0 deletions Tests/CorePromise/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 7fb8a92

Please sign in to comment.