Skip to content

Commit 7fb8a92

Browse files
authored
Merge pull request #1304 from RomanPodymov/v6
More when(guarantees:)
2 parents cea8fb6 + 2d77dc2 commit 7fb8a92

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

Sources/when.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,18 @@ public func when(guarantees: [Guarantee<Void>]) -> Guarantee<Void> {
400400
public func when<U, V>(guarantees gu: Guarantee<U>, _ gv: Guarantee<V>) -> Guarantee<(U, V)> {
401401
return __when([gu.asVoid(), gv.asVoid()]).map(on: nil) { (gu.value!, gv.value!) }
402402
}
403+
404+
/// Waits on all provided Guarantees.
405+
public func when<U, V, W>(guarantees gu: Guarantee<U>, _ gv: Guarantee<V>, _ gw: Guarantee<W>) -> Guarantee<(U, V, W)> {
406+
return __when([gu.asVoid(), gv.asVoid(), gw.asVoid()]).map(on: nil) { (gu.value!, gv.value!, gw.value!) }
407+
}
408+
409+
/// Waits on all provided Guarantees.
410+
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)> {
411+
return __when([gu.asVoid(), gv.asVoid(), gw.asVoid(), gx.asVoid()]).map(on: nil) { (gu.value!, gv.value!, gw.value!, gx.value!) }
412+
}
413+
414+
/// Waits on all provided Guarantees.
415+
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)> {
416+
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!) }
417+
}

Tests/CorePromise/WhenTests.swift

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ class WhenTests: XCTestCase {
137137
let progress = Progress(totalUnitCount: 1)
138138
progress.becomeCurrent(withPendingUnitCount: 1)
139139

140-
when(fulfilled: p1, p2, p3, p4).done { _ in
140+
when(guarantees: p1, p2, p3, p4).done { _ in
141141
XCTAssertEqual(progress.completedUnitCount, 1)
142142
ex.fulfill()
143-
}.silenceWarning()
143+
}
144144

145145
progress.resignCurrent()
146146

@@ -276,4 +276,52 @@ class WhenTests: XCTestCase {
276276
}
277277
waitForExpectations(timeout: 1, handler: nil)
278278
}
279+
280+
func testTripleTupleGuarantees() {
281+
let e1 = expectation(description: "")
282+
let g1 = Guarantee.value(1)
283+
let g2 = Guarantee.value("abc")
284+
let g3 = Guarantee.value( 1.0)
285+
when(guarantees: g1, g2, g3).done { u, v, w in
286+
XCTAssertEqual(1, u)
287+
XCTAssertEqual("abc", v)
288+
XCTAssertEqual(1.0, w)
289+
e1.fulfill()
290+
}
291+
waitForExpectations(timeout: 1, handler: nil)
292+
}
293+
294+
func testQuadrupleTupleGuarantees() {
295+
let e1 = expectation(description: "")
296+
let g1 = Guarantee.value(1)
297+
let g2 = Guarantee.value("abc")
298+
let g3 = Guarantee.value(1.0)
299+
let g4 = Guarantee.value(true)
300+
when(guarantees: g1, g2, g3, g4).done { u, v, w, x in
301+
XCTAssertEqual(1, u)
302+
XCTAssertEqual("abc", v)
303+
XCTAssertEqual(1.0, w)
304+
XCTAssertEqual(true, x)
305+
e1.fulfill()
306+
}
307+
waitForExpectations(timeout: 1, handler: nil)
308+
}
309+
310+
func testQuintupleTupleGuarantees() {
311+
let e1 = expectation(description: "")
312+
let g1 = Guarantee.value(1)
313+
let g2 = Guarantee.value("abc")
314+
let g3 = Guarantee.value(1.0)
315+
let g4 = Guarantee.value(true)
316+
let g5 = Guarantee.value("a" as Character)
317+
when(guarantees: g1, g2, g3, g4, g5).done { u, v, w, x, y in
318+
XCTAssertEqual(1, u)
319+
XCTAssertEqual("abc", v)
320+
XCTAssertEqual(1.0, w)
321+
XCTAssertEqual(true, x)
322+
XCTAssertEqual("a" as Character, y)
323+
e1.fulfill()
324+
}
325+
waitForExpectations(timeout: 1, handler: nil)
326+
}
279327
}

Tests/CorePromise/XCTestManifests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ extension WhenTests {
261261
("testProgress", testProgress),
262262
("testProgressDoesNotExceed100Percent", testProgressDoesNotExceed100Percent),
263263
("testQuadrupleTuple", testQuadrupleTuple),
264+
("testQuadrupleTupleGuarantees", testQuadrupleTupleGuarantees),
264265
("testQuintupleTuple", testQuintupleTuple),
266+
("testQuintupleTupleGuarantees", testQuintupleTupleGuarantees),
265267
("testRejected", testRejected),
266268
("testTripleTuple", testTripleTuple),
269+
("testTripleTupleGuarantees", testTripleTupleGuarantees),
267270
("testUnhandledErrorHandlerDoesNotFire", testUnhandledErrorHandlerDoesNotFire),
268271
("testUnhandledErrorHandlerDoesNotFireForStragglers", testUnhandledErrorHandlerDoesNotFireForStragglers),
269272
("testVoid", testVoid),

0 commit comments

Comments
 (0)