Skip to content

Commit 68facea

Browse files
committed
fixup
1 parent 765e58f commit 68facea

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

Sources/Lifecycle/Lifecycle.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public struct LifecycleHandler {
8181

8282
// MARK: - ServiceLifecycle
8383

84+
/// `ServiceLifecycle` provides a basic mechanism to cleanly startup and shutdown the application, freeing resources in order before exiting.
85+
/// By default, also install shutdown hooks based on `Signal` and backtraces.
8486
public struct ServiceLifecycle {
8587
private let configuration: Configuration
8688

@@ -194,7 +196,7 @@ extension ServiceLifecycle {
194196
}
195197
}
196198

197-
extension ServiceLifecycle: LifecycleRegistrar {
199+
extension ServiceLifecycle: LifecycleTasksConainer {
198200
public func register(_ tasks: [LifecycleTask]) {
199201
self.underlying.register(tasks)
200202
}
@@ -234,7 +236,7 @@ struct ShutdownError: Error {
234236

235237
// MARK: - ComponentLifecycle
236238

237-
/// `Lifecycle` provides a basic mechanism to cleanly startup and shutdown the application, freeing resources in order before exiting.
239+
/// `ComponentLifecycle` provides a basic mechanism to cleanly startup and shutdown a subsystem in a larger application, freeing resources in order before exiting.
238240
public class ComponentLifecycle: LifecycleTask {
239241
public let label: String
240242
private let logger: Logger
@@ -449,7 +451,7 @@ public class ComponentLifecycle: LifecycleTask {
449451
}
450452
}
451453

452-
extension ComponentLifecycle: LifecycleRegistrar {
454+
extension ComponentLifecycle: LifecycleTasksConainer {
453455
public func register(_ tasks: [LifecycleTask]) {
454456
self.stateLock.withLock {
455457
guard case .idle = self.state else {
@@ -462,15 +464,16 @@ extension ComponentLifecycle: LifecycleRegistrar {
462464
}
463465
}
464466

465-
public protocol LifecycleRegistrar {
467+
/// A container of `LifecycleTask`, used to register additional `LifecycleTask`
468+
public protocol LifecycleTasksConainer {
466469
/// Adds a `LifecycleTask` to a `LifecycleTasks` collection.
467470
///
468471
/// - parameters:
469472
/// - tasks: array of `LifecycleTask`.
470473
func register(_ tasks: [LifecycleTask])
471474
}
472475

473-
extension LifecycleRegistrar {
476+
extension LifecycleTasksConainer {
474477
/// Adds a `LifecycleTask` to a `LifecycleTasks` collection.
475478
///
476479
/// - parameters:
@@ -486,7 +489,7 @@ extension LifecycleRegistrar {
486489
/// - start: `Handler` to perform the startup.
487490
/// - shutdown: `Handler` to perform the shutdown.
488491
public func register(label: String, start: LifecycleHandler, shutdown: LifecycleHandler) {
489-
self.register(LifecycleTaskImpl(label: label, start: start, shutdown: shutdown))
492+
self.register(_LifecycleTask(label: label, start: start, shutdown: shutdown))
490493
}
491494

492495
/// Adds a `LifecycleTask` to a `LifecycleTasks` collection.
@@ -499,7 +502,7 @@ extension LifecycleRegistrar {
499502
}
500503
}
501504

502-
internal struct LifecycleTaskImpl: LifecycleTask {
505+
internal struct _LifecycleTask: LifecycleTask {
503506
let label: String
504507
let start: LifecycleHandler
505508
let shutdown: LifecycleHandler

Tests/LifecycleTests/ComponentLifecycleTests.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ final class ComponentLifecycleTests: XCTestCase {
4343

4444
let items = (1 ... Int.random(in: 10 ... 20)).map { index -> LifecycleTask in
4545
let id = "item-\(index)"
46-
return LifecycleTaskImpl(label: id,
47-
start: .sync {
48-
dispatchPrecondition(condition: .onQueue(.global()))
49-
startCalls.append(id)
50-
},
51-
shutdown: .sync {
52-
dispatchPrecondition(condition: .onQueue(.global()))
53-
XCTAssertTrue(startCalls.contains(id))
54-
stopCalls.append(id)
55-
})
46+
return _LifecycleTask(label: id,
47+
start: .sync {
48+
dispatchPrecondition(condition: .onQueue(.global()))
49+
startCalls.append(id)
50+
},
51+
shutdown: .sync {
52+
dispatchPrecondition(condition: .onQueue(.global()))
53+
XCTAssertTrue(startCalls.contains(id))
54+
stopCalls.append(id)
55+
})
5656
}
5757
lifecycle.register(items)
5858

@@ -81,16 +81,16 @@ final class ComponentLifecycleTests: XCTestCase {
8181

8282
let items = (1 ... Int.random(in: 10 ... 20)).map { index -> LifecycleTask in
8383
let id = "item-\(index)"
84-
return LifecycleTaskImpl(label: id,
85-
start: .sync {
86-
dispatchPrecondition(condition: .onQueue(testQueue))
87-
startCalls.append(id)
88-
},
89-
shutdown: .sync {
90-
dispatchPrecondition(condition: .onQueue(testQueue))
91-
XCTAssertTrue(startCalls.contains(id))
92-
stopCalls.append(id)
93-
})
84+
return _LifecycleTask(label: id,
85+
start: .sync {
86+
dispatchPrecondition(condition: .onQueue(testQueue))
87+
startCalls.append(id)
88+
},
89+
shutdown: .sync {
90+
dispatchPrecondition(condition: .onQueue(testQueue))
91+
XCTAssertTrue(startCalls.contains(id))
92+
stopCalls.append(id)
93+
})
9494
}
9595
lifecycle.register(items)
9696

0 commit comments

Comments
 (0)