Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:
jobs:
linux-build:
name: Linux (Swift ${{ matrix.swift }})
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
swift:
Expand Down
8 changes: 8 additions & 0 deletions Sources/when.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public func when(fulfilled thenables: [any Thenable]) -> Promise<[Any]> {
}
#endif

#if swift(>=5.9)
public func when<each U: Thenable>(fulfilled: repeat each U) -> Promise<(repeat (each U).T)> {
var voidPromises: [Promise<Void>] = []
repeat voidPromises.append((each fulfilled).asVoid())
return _when(voidPromises).map(on: nil) { (repeat (each fulfilled).value!) }
}
#endif

/// Wait for all promises in a set to fulfill.
public func when<U: Thenable>(fulfilled promises: U...) -> Promise<Void> where U.T == Void {
return _when(promises)
Expand Down
7 changes: 0 additions & 7 deletions Tests/CorePromise/CancellableErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ class CancellationTests: XCTestCase {
}

func testDoesntCrashSwift() {
#if os(macOS)
// Previously exposed a bridging crash in Swift
// NOTE nobody was brave enough or diligent enough to report this to Apple :{
// NOTE no Linux test since this constructor doesn’t exist there
XCTAssertFalse(NSError().isCancelled)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @mxcl
It looks like this is now also crashing on macOS.

#endif

#if canImport(StoreKit)
if #available(watchOS 6.2, *) {
do {
Expand Down
13 changes: 8 additions & 5 deletions Tests/CorePromise/RaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ class RaceTests: XCTestCase {
func testFulfilledWithNoWinner() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mxcl Don't know why, but it was failing on Android.

enum Error: Swift.Error { case test1, test2 }
let ex = expectation(description: "")
let promises: [Promise<Int>] = [after(seconds: 1).map { _ in throw Error.test1 }, after(seconds: 2).map { _ in throw Error.test2 }]
let promises: [Promise<Int>] = [
after(seconds: 1).map { _ in throw Error.test1 },
after(seconds: 2).map { _ in throw Error.test2 }
]
race(fulfilled: promises).done { _ in
XCTFail()
XCTFail("Done with error")
ex.fulfill()
}.catch {
guard let pmkError = $0 as? PMKError else { return XCTFail() }
guard case .noWinner = pmkError else { return XCTFail() }
guard pmkError.debugDescription == "All thenables passed to race(fulfilled:) were rejected" else { return XCTFail() }
guard let pmkError = $0 as? PMKError else { return XCTFail("error is not PMKError") }
guard case .noWinner = pmkError else { return XCTFail("error is not .noWinner") }
guard pmkError.debugDescription == "All thenables passed to race(fulfilled:) were rejected" else { return XCTFail("Not all thenables passed to race(fulfilled:) were rejected") }
ex.fulfill()
}
wait(for: [ex], timeout: 10)
Expand Down
19 changes: 19 additions & 0 deletions Tests/CorePromise/WhenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ class WhenTests: XCTestCase {
#endif
}

func testParameterPacks() {
#if swift(>=5.9)
let e1 = expectation(description: "")
let p1 = Promise.value(1)
let g2 = Guarantee.value("Hello")
let p3 = Promise.value("world")
let g4 = Guarantee.value(2)

when(fulfilled: p1, g2, p3, g4).done { x1, x2, x3, x4 in
XCTAssertEqual(x1, 1)
XCTAssertEqual(x2, "Hello")
XCTAssertEqual(x3, "world")
XCTAssertEqual(x4, 2)
e1.fulfill()
}.silenceWarning()
waitForExpectations(timeout: 1, handler: nil)
#endif
}

func testDoubleTuple() {
let e1 = expectation(description: "")
let p1 = Promise.value(1)
Expand Down