Skip to content

Commit efff8de

Browse files
committed
Propagate service error when gracefully shutting down
# Motivation Propagate the service error when we shutdown the group after the service threw.
1 parent 496c81c commit efff8de

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/ServiceLifecycle/ServiceGroup.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ public actor ServiceGroup: Sendable {
338338
group: &group,
339339
gracefulShutdownManagers: gracefulShutdownManagers
340340
)
341+
return .failure(error)
341342
} catch {
342343
return .failure(error)
343344
}

Tests/ServiceLifecycleTests/ServiceGroupTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ final class ServiceGroupTests: XCTestCase {
433433
]
434434
)
435435

436-
await withThrowingTaskGroup(of: Void.self) { group in
436+
try await withThrowingTaskGroup(of: Void.self) { group in
437437
group.addTask {
438438
try await serviceGroup.run()
439439
}
@@ -474,6 +474,10 @@ final class ServiceGroupTests: XCTestCase {
474474

475475
// Let's exit from the first service
476476
await service1.resumeRunContinuation(with: .success(()))
477+
478+
try await XCTAsyncAssertThrowsError(await group.next()) {
479+
XCTAssertTrue($0 is ExampleError)
480+
}
477481
}
478482
}
479483

0 commit comments

Comments
 (0)