Skip to content

Commit 281ed7a

Browse files
committed
Resume with Result
1 parent 7d0b437 commit 281ed7a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Sources/IdentifiableContinuation.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ public struct IdentifiableContinuation<T, E>: Sendable, Identifiable where E : E
231231
}
232232
}
233233

234+
public func resume(with result: Result<T, E>) {
235+
switch storage {
236+
case .checked(let continuation):
237+
continuation.resume(with: result)
238+
case .unsafe(let continuation):
239+
continuation.resume(with: result)
240+
}
241+
}
242+
234243
@usableFromInline
235244
enum Storage: Sendable {
236245
case checked(CheckedContinuation<T, E>)

Tests/IdentifiableContinuationTests.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ final class IdentifiableContinuationTests: XCTestCase {
4242
XCTAssertEqual(val, "Fish")
4343
}
4444

45+
func testResumesWithResult() async {
46+
let val = await withIdentifiableContinuation {
47+
$0.resume(with: .success("Chips"))
48+
}
49+
XCTAssertEqual(val, "Chips")
50+
}
51+
4552
func testCancels_After_Created() async {
4653
let waiter = Waiter<String?, Never>()
4754

@@ -91,7 +98,6 @@ final class IdentifiableContinuationTests: XCTestCase {
9198
}
9299
}
93100

94-
95101
func testThrowingCancels_After_Created() async {
96102
let waiter = Waiter<String, Error>()
97103

@@ -137,6 +143,13 @@ final class IdentifiableContinuationTests: XCTestCase {
137143
XCTAssertEqual(val, "Fish")
138144
}
139145

146+
func testUnsafeResumesWithResult() async {
147+
let val = await withIdentifiableUnsafeContinuation {
148+
$0.resume(with: .success("Chips"))
149+
}
150+
XCTAssertEqual(val, "Chips")
151+
}
152+
140153
func testUnsafeCancels_After_Created() async {
141154
let waiter = Waiter<String?, Never>()
142155

0 commit comments

Comments
 (0)