Skip to content

Commit d31c08e

Browse files
authored
readme improvements (#28)
motivation: prepare to OSS changes: edit the exampe to make the comments clearer and simpler
1 parent 2523627 commit d31c08e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,45 @@ import ServiceLauncher
3535
// initialize the lifecycle container
3636
var lifecycle = Lifecycle()
3737

38-
// register a resource that should be shutdown when the application exists.
39-
// in this case, we are registering a SwiftNIO EventLoopGroup
38+
// register a resource that should be shut down when the application exits.
39+
//
40+
// in this case, we are registering a SwiftNIO `EventLoopGroup`
4041
// and passing its `syncShutdownGracefully` function to be called on shutdown
4142
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
4243
lifecycle.registerShutdown(
4344
name: "eventLoopGroup",
4445
eventLoopGroup.syncShutdownGracefully
4546
)
4647

47-
// register another resource that should be shutdown when the application exits.
48-
// in this case, we are registering an HTTPClient
48+
// register another resource that should be shut down when the application exits.
49+
//
50+
// in this case, we are registering an `HTTPClient`
4951
// and passing its `syncShutdown` function to be called on shutdown
5052
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
5153
lifecycle.registerShutdown(
52-
name: "HTTPClient",
54+
name: "httpClient",
5355
httpClient.syncShutdown
5456
)
5557

5658
// start the application
59+
//
5760
// start handlers passed using the `register` function
58-
// will be called in the order the items were registered in
61+
// will be called in the order they were registered in
5962
lifecycle.start() { error in
60-
// this is the start completion handler.
61-
// if an error occurred you can log it here
63+
// start completion handler.
64+
// if a startup error occurred you can capture it here
6265
if let error = error {
6366
logger.error("failed starting \(self) ☠️: \(error)")
6467
} else {
6568
logger.info("\(self) started successfully 🚀")
6669
}
6770
}
68-
// wait for the application to exist
69-
// this is a blocking operation that typically waits for
70-
// for a signal configured at lifecycle.start (default is `INT` and `TERM`)
71-
// or another thread calling lifecycle.shutdown (atypical)
71+
// wait for the application to exit
72+
//
73+
// this is a blocking operation that typically waits for a signal
74+
// the signal can be configured at `lifecycle.start`, and defaults to `INT` and `TERM`
7275
// shutdown handlers passed using the `register` or `registerShutdown` functions
73-
// will be called in the reverse order the items were registered in
76+
// will be called in the reverse order they were registered in
7477
lifecycle.wait()
7578
```
7679

@@ -203,7 +206,7 @@ lifecycle.register(
203206
start: .eventLoopFuture(foo.start),
204207
shutdown: .eventLoopFuture(foo.shutdown)
205208
)
206-
```
209+
```
207210

208211
-------
209212

0 commit comments

Comments
 (0)