You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Swift Service Lifecycle
2
2
3
3
Swift Service Lifecycle provides a basic mechanism to cleanly start up and shut down the application, freeing resources in order before exiting.
4
-
It also provides a `Signal`-based shutdown hook, to shutdown on signals like `TERM` or `INT`.
4
+
It also provides a `Signal`-based shutdown hook, to shut down on signals like `TERM` or `INT`.
5
5
6
6
Swift Service Lifecycle was designed with the idea that every application has some startup and shutdown workflow-like-logic which is often sensitive to failure and hard to get right.
7
7
The library codes this common need in a safe and reusable way that is non-framework specific, and designed to be integrated with any server framework or directly in an application.
@@ -85,15 +85,15 @@ lifecycle.wait()
85
85
The main types in the library are `ServiceLifecycle` and `ComponentLifecycle`.
86
86
87
87
`ServiceLifecycle` is the most commonly used type.
88
-
It is designed to manage the toplevel Application (Service) lifecycle,
88
+
It is designed to manage the top-level Application (Service) lifecycle,
89
89
and in addition to managing the startup and shutdown flows it can also set up `Signal` trap for shutdown and install backtraces.
90
90
91
91
`ComponentLifecycle` manages a state machine representing the startup and shutdown logic flow.
92
92
In larger Applications (Services) `ComponentLifecycle` can be used to manage the lifecycle of subsystems, such that `ServiceLifecycle` can start and shutdown `ComponentLifecycle`s.
93
93
94
94
### Registering items
95
95
96
-
`ServiceLifecycle` and `ComponentLifecycle` are containers for `LifecycleTask`s which need to be registered using a `LifecycleHandler` - a container for synchronous or asynchronous closures.
96
+
`ServiceLifecycle` and `ComponentLifecycle` are containers for `LifecycleTask`s which need to be registered using a `LifecycleHandler` - a container for synchronous or asynchronous closures.
97
97
98
98
Synchronous handlers are defined as `() throws -> Void`.
*`shutdownSignal`: Defines what, if any, signals to trap for invoking shutdown. By default, `INT` and `TERM` are trapped.
158
158
159
-
*`installBacktrace`: Defines if to install a crash signal trap that prints backtraces. This is especially useful for application running on Linux since Swift does not provide backtraces on Linux out of the box. This functionality is provided via the [Swift Backtrace](https://github.com/swift-server/swift-backtrace) library.
159
+
*`installBacktrace`: Defines if to install a crash signal trap that prints backtraces. This is especially useful for applications running on Linux since Swift does not provide backtraces on Linux out of the box. This functionality is provided via the [Swift Backtrace](https://github.com/swift-server/swift-backtrace) library.
160
160
161
161
### Starting the lifecycle
162
162
163
-
Use `start` function to start the application.
163
+
Use the `start` function to start the application.
164
164
Start handlers passed using the `register` function will be called in the order the items were registered in.
165
165
166
166
`start` is an asynchronous operation.
@@ -178,7 +178,7 @@ lifecycle.start { error in
178
178
179
179
### Shutdown
180
180
181
-
Typical use of the library is to call on `wait` after calling `start`.
181
+
The typical use of the library is to call on `wait` after calling `start`.
0 commit comments