Skip to content

Commit b833f28

Browse files
committed
redame
1 parent 164106e commit b833f28

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,32 @@ In more complex cases, when `Signal`-trapping-based shutdown is not appropriate,
214214

215215
`shutdown` is an asynchronous operation. Errors will be logged and bubbled up to the provided completion handler.
216216

217+
### Stateful handlers
218+
219+
In some cases it is useful to have the Start handlers return a state that can be passed on to the Shutdown handlers for shutdown.
220+
For example, when establishing some sort of a connection that needs to be closed at shutdown.
221+
222+
```swift
223+
struct Foo {
224+
func start() throws -> Connection {
225+
return ...
226+
}
227+
228+
func shutdown(state: Connection) throws {
229+
...
230+
}
231+
}
232+
```
233+
234+
```swift
235+
let foo = ...
236+
lifecycle.registerStateful(
237+
label: "foo",
238+
start: .sync(foo.start),
239+
shutdown: .sync(foo.shutdown)
240+
)
241+
```
242+
217243
### Complex Systems and Nesting of Subsystems
218244

219245
In larger Applications (Services) `ComponentLifecycle` can be used to manage the lifecycle of subsystems, such that `ServiceLifecycle` can start and shutdown `ComponentLifecycle`s.

0 commit comments

Comments
 (0)