Skip to content

Commit 0503127

Browse files
authored
Update TerminationBehavior doc comments and notes (#165)
* Mention `TerminationBehavior` in library adoption docs `ServiceGroupConfiguration.ServiceConfiguration.TerminationBehavior` did not seem to be mentioned in the docs and specifically library adoption docs gave the impression that cancellation on returning from `run` is the only option. * Update relevant documentation
1 parent 0907d4a commit 0503127

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

Sources/ServiceLifecycle/Docs.docc/How to adopt ServiceLifecycle in applications.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ By default the ``ServiceGroup`` is cancelling the whole group if the one service
236236
returns or throws. However, in some scenarios this is totally expected e.g. when
237237
the ``ServiceGroup`` is used in a CLI tool to orchestrate some services while a
238238
command is handled. To customize the behavior you set the
239-
``ServiceGroupConfiguration/ServiceConfiguration/returnBehaviour`` and
240-
``ServiceGroupConfiguration/ServiceConfiguration/throwBehaviour``. Both of them
239+
``ServiceGroupConfiguration/ServiceConfiguration/successTerminationBehavior`` and
240+
``ServiceGroupConfiguration/ServiceConfiguration/failureTerminationBehavior``. Both of them
241241
offer three different options. The default behavior for both is
242242
``ServiceGroupConfiguration/ServiceConfiguration/TerminationBehavior/cancelGroup``.
243243
You can also choose to either ignore if a service returns/throws by setting it
@@ -261,7 +261,11 @@ struct Application {
261261
configuration: .init(
262262
services: [
263263
.init(service: telemetryService),
264-
.init(service: httpServer, returnBehavior: .shutdownGracefully, throwBehavior: .shutdownGracefully)
264+
.init(
265+
service: httpServer,
266+
successTerminationBehavior: .shutdownGracefully,
267+
failureTerminationBehavior: .shutdownGracefully
268+
)
265269
],
266270
logger: logger
267271
),

Sources/ServiceLifecycle/Docs.docc/How to adopt ServiceLifecycle in libraries.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ public actor TCPEchoClient: Service {
9090

9191
Since the `run()` method contains long running work, returning from it is seen
9292
as a failure and will lead to the ``ServiceGroup`` cancelling all other services
93-
by cancelling the task that is running their respective `run()` method.
93+
by cancelling the task that is running their respective `run()` method, unless
94+
specified otherwise in ``ServiceGroupConfiguration/ServiceConfiguration/successTerminationBehavior``
95+
and ``ServiceGroupConfiguration/ServiceConfiguration/failureTerminationBehavior``.
9496

9597
### Cancellation
9698

Sources/ServiceLifecycle/Service.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public protocol Service: Sendable {
2020
/// - Handling incoming connections and requests
2121
/// - Background refreshes
2222
///
23-
/// - Important: Returning or throwing from this method is indicating a failure of the service and will cause the ``ServiceGroup``
24-
/// to cancel the child tasks of all other running services.
23+
/// - Important: Returning or throwing from this method indicates the service should stop and will cause the
24+
/// ``ServiceGroup`` to follow behaviors for the child tasks of all other running services specified in
25+
/// ``ServiceGroupConfiguration/ServiceConfiguration/successTerminationBehavior`` and
26+
/// ``ServiceGroupConfiguration/ServiceConfiguration/failureTerminationBehavior``.
2527
func run() async throws
2628
}

Sources/ServiceLifecycle/ServiceGroupConfiguration.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public struct ServiceGroupConfiguration: Sendable {
4747
}
4848

4949
public struct ServiceConfiguration: Sendable {
50+
/// The behavior to follow when the service finishes its ``Service/run()`` method via returning or throwing.
5051
public struct TerminationBehavior: Sendable, CustomStringConvertible {
5152
internal enum _TerminationBehavior {
5253
case cancelGroup
@@ -72,19 +73,19 @@ public struct ServiceGroupConfiguration: Sendable {
7273
}
7374
}
7475

75-
/// The service.
76+
/// The service to which the initialized configuration applies.
7677
public var service: any Service
77-
/// The behavior when the service returns from its `run()` method.
78+
/// The behavior when the service returns from its ``Service/run()`` method.
7879
public var successTerminationBehavior: TerminationBehavior
79-
/// The behavior when the service throws from its `run()` method.
80+
/// The behavior when the service throws from its ``Service/run()`` method.
8081
public var failureTerminationBehavior: TerminationBehavior
8182

8283
/// Initializes a new ``ServiceGroupConfiguration/ServiceConfiguration``.
8384
///
8485
/// - Parameters:
85-
/// - service: The service.
86-
/// - successTerminationBehavior: The behavior when the service returns from its `run()` method.
87-
/// - failureTerminationBehavior: The behavior when the service throws from its `run()` method.
86+
/// - service: The service to which the initialized configuration applies.
87+
/// - successTerminationBehavior: The behavior when the service returns from its ``Service/run()`` method.
88+
/// - failureTerminationBehavior: The behavior when the service throws from its ``Service/run()`` method.
8889
public init(
8990
service: any Service,
9091
successTerminationBehavior: TerminationBehavior = .cancelGroup,

0 commit comments

Comments
 (0)