Skip to content

Commit 55b527c

Browse files
authored
Resume continuation on cancellation when using .async() (#1334)
* Resume continuation on cancellation when using .async() * PromiseKit 8.1.2
1 parent 4c31ef1 commit 55b527c

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

Diff for: PromiseKit.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "PromiseKit"
33

4-
s.version = '8.1.1'
4+
s.version = '8.1.2'
55

66
s.source = {
77
:git => "https://github.com/mxcl/#{s.name}.git",

Diff for: PromiseKit.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@
957957
CLANG_WARN_UNREACHABLE_CODE = YES;
958958
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
959959
COPY_PHASE_STRIP = NO;
960-
CURRENT_PROJECT_VERSION = 8.1.1;
960+
CURRENT_PROJECT_VERSION = 8.1.2;
961961
DEBUG_INFORMATION_FORMAT = dwarf;
962962
DYLIB_COMPATIBILITY_VERSION = 1;
963963
DYLIB_CURRENT_VERSION = 1;
@@ -1020,7 +1020,7 @@
10201020
CLANG_WARN_UNREACHABLE_CODE = YES;
10211021
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
10221022
COPY_PHASE_STRIP = NO;
1023-
CURRENT_PROJECT_VERSION = 8.1.1;
1023+
CURRENT_PROJECT_VERSION = 8.1.2;
10241024
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
10251025
DYLIB_COMPATIBILITY_VERSION = 1;
10261026
DYLIB_CURRENT_VERSION = 1;

Diff for: Sources/Async.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public extension Promise {
1717
try await withCheckedThrowingContinuation { continuation in
1818
done { value in
1919
continuation.resume(returning: value)
20-
}.catch { error in
20+
}.catch(policy: .allErrors) { error in
2121
continuation.resume(throwing: error)
2222
}
2323
}

Diff for: Tests/CorePromise/AsyncTests.swift

+50
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,55 @@ class AsyncTests: XCTestCase {
9494

9595
}
9696
#endif
97+
98+
#if swift(>=5.5)
99+
#if canImport(_Concurrency)
100+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
101+
func testAsyncPromiseCancel() async throws {
102+
do {
103+
let p = after(seconds: 0).done { _ in
104+
throw LocalError.cancel
105+
}.done {
106+
XCTFail()
107+
}
108+
p.catch { _ in
109+
XCTFail()
110+
}
111+
try await p.async()
112+
XCTAssert(false)
113+
} catch {
114+
guard let cancellableError = error as? CancellableError else { return XCTFail("Unexpected error type") }
115+
XCTAssertTrue(cancellableError.isCancelled)
116+
}
117+
}
118+
119+
@available(iOS, deprecated: 13.0)
120+
@available(macOS, deprecated: 10.15)
121+
@available(tvOS, deprecated: 13.0)
122+
@available(watchOS, deprecated: 6.0)
123+
func testAsyncPromiseCancel() {
124+
125+
}
126+
#else
127+
func testAsyncPromiseCancel() {
128+
129+
}
130+
#endif
131+
#else
132+
func testAsyncPromiseCancel() {
133+
134+
}
135+
#endif
97136
}
98137

138+
private enum LocalError: CancellableError {
139+
case notCancel
140+
case cancel
141+
142+
var isCancelled: Bool {
143+
switch self {
144+
case .notCancel: return false
145+
case .cancel: return true
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)