Skip to content

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Apr 3, 2020

proposal for #14, do not merge

the names are terrible, but lets agree on the concept, then find great names

@tomerd tomerd linked an issue Apr 3, 2020 that may be closed by this pull request
@tomerd tomerd requested review from ddossot, ktoso, weissi and yim-lee April 3, 2020 22:22
@tomerd tomerd force-pushed the nesting branch 3 times, most recently from a271b50 to 943b33f Compare April 3, 2020 22:44
@tomerd tomerd linked an issue Apr 3, 2020 that may be closed by this pull request
tomerd added 2 commits April 4, 2020 00:56
motivation: in some cases users may want access to the shutdown errors

changes: add optoinal callback to shutdown providing access to shutdown errors
motivation: add ability to create a hirearchy of lifecycles to help manage more complex systems

changes:
* define top-level lifcycle where signal handling and backtraces are handled
* conform Lifecycle to LifecycleItem so that lifecycles can be nested
* change shutdown to return an error to better conform with LifecycleItem api
import Dispatch
import Logging

public struct TopLevelLifecycle {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #14 (comment) the names ServiceLifecycle and ComponentLifecycle surfaced -- I think those are good names 👍 How about using those.

Would the module become swift-service-lifecycle?

public struct TopLevelLifecycle {
private let lifecycle = Lifecycle(label: "\(TopLevelLifecycle.self)")

/// Starts the provided `LifecycleItem` array and waits (blocking) until a shutdown `Signal` is captured or `Lifecycle.shutdown` is called on another thread.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Item has been nagging me a bit... are those not more like "tasks" to be or "phases"? Item does not feel like it is "part of" Lifecycle.

LifecycleTask would be my preference but could survive with existing, if people like it strongly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like task

/// - parameters:
/// - configuration: Defines lifecycle `Configuration`
/// - callback: The handler which is called after the start operation completes. The parameter will be `nil` on success and contain the `Error` otherwise.
public func start(configuration: Configuration = .init(), callback: @escaping (Error?) -> Void) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public func start(configuration: Configuration = .init(), callback: @escaping (Error?) -> Void) {
public func start(configuration: Configuration = .init(), _ callback: @escaping (Error?) -> Void) {

in alignment with #26

///
/// - parameters:
/// - callback: The handler which is called after the start operation completes. The parameter will be `nil` on success and contain the `Error` otherwise.
public func shutdown(callback: @escaping (Error?) -> Void = { _ in }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public func shutdown(callback: @escaping (Error?) -> Void = { _ in }) {
public func shutdown(_ callback: @escaping (Error?) -> Void = { _ in }) {

items2.forEach { XCTAssertEqual($0.state, .shutdown, "expected item to be shutdown, but \($0.state)") }
items3.forEach { XCTAssertEqual($0.state, .shutdown, "expected item to be shutdown, but \($0.state)") }
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me in general.

Naming wise ServiceLifecycle and ComponentLifecycle sound good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A component having more components could be a thing but not strictly necessary...

@ktoso ktoso mentioned this pull request Apr 8, 2020
///
/// - parameters:
/// - items: one or more `LifecycleItem`.
func register(_ items: [LifecycleItem]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't these need to be public func ? The tests seem to all use @testable import which might hide this?

@tomerd
Copy link
Contributor Author

tomerd commented Apr 10, 2020

replaced by #34

@tomerd tomerd closed this Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is ServiceLauncher a good name? docs about nesting ServiceLaunchers

3 participants