Skip to content

Commit 2dac25d

Browse files
authored
Add convenience init to the group (#154)
# Motivation Right now creating a `ServiceGroup` always requires creating a `ServiceGroupConfiguration`. This is making the barrier to use the group higher than needed for the 99% use-case. # Modification This PR adds a new init on the `ServiceGroup` that takes an array of services, graceful shutdown & cancellation signals and the logger. # Result Easier use of the service group for the 99% use-case.
1 parent 06ec110 commit 2dac25d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Sources/ServiceLifecycle/ServiceGroup.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ public actor ServiceGroup: Sendable {
5959
self.loggingConfiguration = configuration.logging
6060
}
6161

62+
/// Initializes a new ``ServiceGroup``.
63+
///
64+
/// - Parameters:
65+
/// - services: The groups's service configurations.
66+
/// - gracefulShutdownSignals: The signals that lead to graceful shutdown.
67+
/// - cancellationSignals: The signals that lead to cancellation.
68+
/// - logger: The group's logger.
69+
public init(
70+
services: [any Service],
71+
gracefulShutdownSignals: [UnixSignal] = [],
72+
cancellationSignals: [UnixSignal] = [],
73+
logger: Logger
74+
) {
75+
let configuration = ServiceGroupConfiguration(
76+
services: services.map { ServiceGroupConfiguration.ServiceConfiguration(service: $0) },
77+
gracefulShutdownSignals: gracefulShutdownSignals,
78+
cancellationSignals: cancellationSignals,
79+
logger: logger
80+
)
81+
82+
self.init(configuration: configuration)
83+
}
84+
6285
@available(*, deprecated)
6386
public init(
6487
services: [any Service],

0 commit comments

Comments
 (0)