Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More when(guarantees:) #1304

Merged
merged 2 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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