Skip to content

Commit 4c5efa9

Browse files
authored
adding abstracts and organization to methods (#205)
A little bit of docs cleanup - adding abstracts for deprecated methods and curating them (organizing them) to the bottom of the relevant lists.
1 parent e718730 commit 4c5efa9

File tree

8 files changed

+134
-25
lines changed

8 files changed

+134
-25
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ``ServiceLifecycle/ServiceGroupConfiguration/LoggingConfiguration``
2+
3+
## Topics
4+
5+
### Creating a logging configuration
6+
7+
- ``init()``
8+
9+
### Inspecting a service group configuration
10+
11+
- ``keys``
12+
- ``Keys-swift.struct``
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ``ServiceLifecycle/ServiceGroupConfiguration/ServiceConfiguration``
2+
3+
## Topics
4+
5+
### Creating a service configuration
6+
7+
- ``init(service:successTerminationBehavior:failureTerminationBehavior:)``
8+
9+
### Inspecting a service configuration
10+
11+
- ``service``
12+
- ``failureTerminationBehavior``
13+
- ``successTerminationBehavior``
14+
- ``TerminationBehavior``
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ``ServiceLifecycle/ServiceGroup``
2+
3+
## Topics
4+
5+
### Creating a service group
6+
7+
- ``init(configuration:)``
8+
- ``init(services:gracefulShutdownSignals:cancellationSignals:logger:)``
9+
- ``init(services:configuration:logger:)``
10+
11+
### Adding to a service group
12+
13+
- ``addServiceUnlessShutdown(_:)-r47h``
14+
- ``addServiceUnlessShutdown(_:)-9jpoj``
15+
16+
### Running a service group
17+
18+
- ``run(file:line:)``
19+
- ``run()``
20+
- ``triggerGracefulShutdown()``
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# ``ServiceLifecycle/ServiceGroupConfiguration``
2+
3+
## Topics
4+
5+
### Creating a service group configuration
6+
7+
- ``init(services:logger:)-309oa``
8+
- ``init(services:logger:)-2mhze``
9+
- ``init(gracefulShutdownSignals:)``
10+
11+
### Creating a new service group configuration with signal handlers
12+
13+
- ``init(services:gracefulShutdownSignals:cancellationSignals:logger:)-9uhzu``
14+
- ``init(services:gracefulShutdownSignals:cancellationSignals:logger:)-1noxs``
15+
16+
### Inspecting the service group services
17+
18+
- ``services``
19+
- ``ServiceConfiguration``
20+
21+
### Inspecting the service group logging
22+
23+
- ``logging``
24+
- ``LoggingConfiguration``
25+
- ``logger``
26+
27+
### Inspecting the service group signal handling
28+
29+
- ``cancellationSignals``
30+
- ``maximumCancellationDuration``
31+
- ``gracefulShutdownSignals``
32+
- ``maximumGracefulShutdownDuration``

Sources/ServiceLifecycle/Docs.docc/index.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@ let package = Package(
7676

7777
- ``ServiceGroup``
7878
- ``ServiceGroupConfiguration``
79+
- ``ServiceGroupError``
7980

8081
### Graceful Shutdown
8182

82-
- ``withGracefulShutdownHandler(operation:onGracefulShutdown:)``
83-
- ``cancelOnGracefulShutdown(_:)``
84-
85-
### Errors
83+
- ``gracefulShutdown()``
84+
- ``cancelWhenGracefulShutdown(_:)``
85+
- ``withTaskCancellationOrGracefulShutdownHandler(isolation:operation:onCancelOrGracefulShutdown:)``
86+
- ``withGracefulShutdownHandler(isolation:operation:onGracefulShutdown:)``
87+
- ``AsyncCancelOnGracefulShutdownSequence``
8688

87-
- ``ServiceGroupError``
89+
- ``cancelOnGracefulShutdown(_:)``
90+
- ``withGracefulShutdownHandler(operation:onGracefulShutdown:)``
91+
- ``withGracefulShutdownHandler(operation:onGracefulShutdown:)-1x21p``
92+
- ``withTaskCancellationOrGracefulShutdownHandler(operation:onCancelOrGracefulShutdown:)-81m01``

Sources/ServiceLifecycle/GracefulShutdown.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public func withGracefulShutdownHandler<T>(
5858
return try await operation()
5959
}
6060

61+
/// Execute an operation with a graceful shutdown handler that’s immediately invoked if the current task is shutting down gracefully.
62+
///
63+
/// Use ``withGracefulShutdownHandler(isolation:operation:onGracefulShutdown:)`` instead.
6164
@available(*, deprecated, message: "Use the method with the isolation parameter instead.")
6265
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
6366
@_disfavoredOverload
@@ -142,6 +145,11 @@ public func withTaskCancellationOrGracefulShutdownHandler<T>(
142145
handler()
143146
}
144147
}
148+
149+
/// Execute an operation with a graceful shutdown or task cancellation handler that’s immediately invoked if the current task is
150+
/// shutting down gracefully or has been cancelled.
151+
///
152+
/// Use ``withTaskCancellationOrGracefulShutdownHandler(isolation:operation:onCancelOrGracefulShutdown:)`` instead.
145153
@available(*, deprecated, message: "Use the method with the isolation parameter instead.")
146154
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
147155
@_disfavoredOverload
@@ -156,6 +164,10 @@ public func withTaskCancellationOrGracefulShutdownHandler<T>(
156164
}
157165
}
158166
#else
167+
/// Execute an operation with a graceful shutdown or task cancellation handler that’s immediately invoked if the current task is
168+
/// shutting down gracefully or has been cancelled.
169+
///
170+
/// Use ``withTaskCancellationOrGracefulShutdownHandler(isolation:operation:onCancelOrGracefulShutdown:)`` instead.
159171
@available(*, deprecated, message: "Use the method with the isolation parameter instead.")
160172
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
161173
@_disfavoredOverload
@@ -244,6 +256,7 @@ public func cancelWhenGracefulShutdown<T: Sendable>(
244256

245257
/// Cancels the closure when a graceful shutdown was triggered.
246258
///
259+
/// Use ``cancelWhenGracefulShutdown(_:)`` instead.
247260
/// - Parameter operation: The actual operation.
248261
#if compiler(>=6.0)
249262
@available(*, deprecated, renamed: "cancelWhenGracefulShutdown")

Sources/ServiceLifecycle/ServiceGroup.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Logging
1616
import UnixSignals
1717
import AsyncAlgorithms
1818

19-
/// A ``ServiceGroup`` is responsible for running a number of services, setting up signal handling and signalling graceful shutdown to the services.
19+
/// A service group is responsible for running a number of services, setting up signal handling and signalling graceful shutdown to the services.
2020
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2121
public actor ServiceGroup: Sendable, Service {
2222
/// The internal state of the ``ServiceGroup``.
@@ -47,7 +47,7 @@ public actor ServiceGroup: Sendable, Service {
4747
/// The current state of the group.
4848
private var state: State
4949

50-
/// Initializes a new ``ServiceGroup``.
50+
/// Creates a service group.
5151
///
5252
/// - Parameters:
5353
/// - configuration: The group's configuration
@@ -68,7 +68,7 @@ public actor ServiceGroup: Sendable, Service {
6868
self.maximumCancellationDuration = configuration._maximumCancellationDuration
6969
}
7070

71-
/// Initializes a new ``ServiceGroup``.
71+
/// Creates a service group.
7272
///
7373
/// - Parameters:
7474
/// - services: The groups's service configurations.
@@ -91,6 +91,9 @@ public actor ServiceGroup: Sendable, Service {
9191
self.init(configuration: configuration)
9292
}
9393

94+
/// Creates a service group.
95+
///
96+
/// Use ``init(services:gracefulShutdownSignals:cancellationSignals:logger:)`` instead.
9497
@available(*, deprecated, renamed: "init(services:gracefulShutdownSignals:cancellationSignals:logger:)")
9598
public init(
9699
services: [any Service],
@@ -109,7 +112,7 @@ public actor ServiceGroup: Sendable, Service {
109112
self.maximumCancellationDuration = configuration._maximumCancellationDuration
110113
}
111114

112-
/// Adds a new service to the group.
115+
/// Adds a service to the group.
113116
///
114117
/// If the group is currently running, the added service will be started immediately.
115118
/// If the group is gracefully shutting down, cancelling, or already finished, the added service will not be started.
@@ -131,7 +134,7 @@ public actor ServiceGroup: Sendable, Service {
131134
}
132135
}
133136

134-
/// Adds a new service to the group.
137+
/// Adds a service to the group.
135138
///
136139
/// If the group is currently running, the added service will be started immediately.
137140
/// If the group is gracefully shutting down, cancelling, or already finished, the added service will not be started.
@@ -152,8 +155,8 @@ public actor ServiceGroup: Sendable, Service {
152155
}
153156

154157
/// Runs all the services by spinning up a child task per service.
155-
/// Furthermore, this method sets up the correct signal handlers
156-
/// for graceful shutdown.
158+
///
159+
/// Furthermore, this method sets up the correct signal handlers for graceful shutdown.
157160
public func run(file: String = #file, line: Int = #line) async throws {
158161
switch self.state {
159162
case .initial(var services):

Sources/ServiceLifecycle/ServiceGroupConfiguration.swift

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import UnixSignals
1717

1818
let deprecatedLoggerLabel = "service-lifecycle-deprecated-method-logger"
1919

20-
/// The configuration for the ``ServiceGroup``.
20+
/// The configuration for the service group.
2121
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2222
public struct ServiceGroupConfiguration: Sendable {
2323
/// The group's logging configuration.
2424
public struct LoggingConfiguration: Sendable {
25+
/// The keys to use for logging
2526
public struct Keys: Sendable {
2627
/// The logging key used for logging the unix signal.
2728
public var signalKey = "sl-signal"
@@ -36,19 +37,23 @@ public struct ServiceGroupConfiguration: Sendable {
3637
/// The logging key used for logging an error.
3738
public var errorKey = "sl-error"
3839

39-
/// Initializes a new ``ServiceGroupConfiguration/LoggingConfiguration/Keys``.
40+
/// Creates a new set of keys.
4041
public init() {}
4142
}
4243

4344
/// The keys used for logging.
4445
public var keys = Keys()
4546

46-
/// Initializes a new ``ServiceGroupConfiguration/LoggingConfiguration``.
47+
/// Creates a new logging configuration.
4748
public init() {}
4849
}
4950

51+
/// A service configuration.
5052
public struct ServiceConfiguration: Sendable {
51-
/// The behavior to follow when the service finishes its ``Service/run()`` method via returning or throwing.
53+
54+
/// The behavior to follow when the service finishes running.
55+
///
56+
/// This describes what the service lifecycle code does when a service's run method returns or throws.
5257
public struct TerminationBehavior: Sendable, CustomStringConvertible {
5358
internal enum _TerminationBehavior {
5459
case cancelGroup
@@ -58,10 +63,14 @@ public struct ServiceGroupConfiguration: Sendable {
5863

5964
internal let behavior: _TerminationBehavior
6065

66+
/// Cancel the service group.
6167
public static let cancelGroup = Self(behavior: .cancelGroup)
68+
/// Gracefully shut down the service group.
6269
public static let gracefullyShutdownGroup = Self(behavior: .gracefullyShutdownGroup)
70+
/// Ignore the completion of the service.
6371
public static let ignore = Self(behavior: .ignore)
6472

73+
/// A string representation of the behavior when a service finishes running.
6574
public var description: String {
6675
switch self.behavior {
6776
case .cancelGroup:
@@ -76,17 +85,17 @@ public struct ServiceGroupConfiguration: Sendable {
7685

7786
/// The service to which the initialized configuration applies.
7887
public var service: any Service
79-
/// The behavior when the service returns from its ``Service/run()`` method.
88+
/// The behavior when the service returns from its run method.
8089
public var successTerminationBehavior: TerminationBehavior
81-
/// The behavior when the service throws from its ``Service/run()`` method.
90+
/// The behavior when the service throws from its run method.
8291
public var failureTerminationBehavior: TerminationBehavior
8392

84-
/// Initializes a new ``ServiceGroupConfiguration/ServiceConfiguration``.
93+
/// Initializes a new service configuration.
8594
///
8695
/// - Parameters:
8796
/// - service: The service to which the initialized configuration applies.
88-
/// - successTerminationBehavior: The behavior when the service returns from its ``Service/run()`` method.
89-
/// - failureTerminationBehavior: The behavior when the service throws from its ``Service/run()`` method.
97+
/// - successTerminationBehavior: The behavior when the service returns from its run method.
98+
/// - failureTerminationBehavior: The behavior when the service throws from its run method.
9099
public init(
91100
service: any Service,
92101
successTerminationBehavior: TerminationBehavior = .cancelGroup,
@@ -166,7 +175,7 @@ public struct ServiceGroupConfiguration: Sendable {
166175

167176
internal var _maximumCancellationDuration: (secondsComponent: Int64, attosecondsComponent: Int64)?
168177

169-
/// Initializes a new ``ServiceGroupConfiguration``.
178+
/// Creates a new service group configuration from the service configurations you provide.
170179
///
171180
/// - Parameters:
172181
/// - services: The groups's service configurations.
@@ -179,7 +188,7 @@ public struct ServiceGroupConfiguration: Sendable {
179188
self.logger = logger
180189
}
181190

182-
/// Initializes a new ``ServiceGroupConfiguration``.
191+
/// Creates a new service group configuration from service configurations you provide with cancellation and shutdown signals.
183192
///
184193
/// - Parameters:
185194
/// - services: The groups's service configurations.
@@ -198,7 +207,7 @@ public struct ServiceGroupConfiguration: Sendable {
198207
self.cancellationSignals = cancellationSignals
199208
}
200209

201-
/// Initializes a new ``ServiceGroupConfiguration``.
210+
/// Creates a new service group configuration from services you provide.
202211
///
203212
/// - Parameters:
204213
/// - services: The groups's services.
@@ -211,7 +220,7 @@ public struct ServiceGroupConfiguration: Sendable {
211220
self.logger = logger
212221
}
213222

214-
/// Initializes a new ``ServiceGroupConfiguration``.
223+
/// Creates a new service group configuration from services you provide with cancellation and shutdown signals..
215224
///
216225
/// - Parameters:
217226
/// - services: The groups's services.
@@ -230,6 +239,7 @@ public struct ServiceGroupConfiguration: Sendable {
230239
self.cancellationSignals = cancellationSignals
231240
}
232241

242+
/// Initializes a new service group configuration.
233243
@available(*, deprecated)
234244
public init(gracefulShutdownSignals: [UnixSignal]) {
235245
self.services = []

0 commit comments

Comments
 (0)