mirror of
https://github.com/swift-server/swift-service-lifecycle
synced 2026-11-27 05:04:26 +00:00
1.0.0-alpha.1
motivation: make API easier to use changes: add default value to configuraiton argument
SwiftServiceLauncher
SwiftServiceLauncher provides a basic mechanism to cleanly start up and shut down the application, freeing resources in order before exiting. It also provides a Signal based shutdown hook, to shutdown on signals like TERM or INT.
SwiftServiceLauncher is non-framework specific, designed to be integrated with any server framework or directly in an application.
Usage
var lifecycle = Lifecycle()
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
lifecycle.registerShutdown(
name: "eventLoopGroup",
eventLoopGroup.syncShutdownGracefully
)
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
lifecycle.registerShutdown(
name: "HTTPClient",
httpClient.syncShutdown
)
lifecycle.start() { error in
if let error = error {
logger.error("failed starting \(self) ☠️: \(error)")
} else {
logger.info("\(self) started successfully 🚀")
}
}
lifecycle.wait()
Description
Mirror of github.com/swift-server/swift-service-lifecycle
1.1 MiB
0 Stars
1 Watchers
0 Forks
Languages
Swift
100%