tomer doron ae96513515 add default config (#7)
motivation: make API easier to use

changes: add default value to configuraiton argument
2020-03-27 16:27:28 -07:00
2020-03-20 12:45:06 -07:00
2020-03-18 11:56:30 -07:00
2020-03-27 16:27:28 -07:00
2020-03-23 11:35:55 -07:00
2020-03-18 11:56:30 -07:00
2020-03-18 11:56:30 -07:00
2020-03-20 12:45:06 -07:00
2020-03-18 11:56:30 -07:00
2020-03-18 11:56:30 -07:00
2020-03-18 11:56:30 -07:00
2020-03-18 11:56:30 -07:00
2020-03-23 11:35:55 -07:00

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()
S
Description
Mirror of github.com/swift-server/swift-service-lifecycle
Readme Apache-2.0
1.1 MiB
0 Stars 1 Watchers 0 Forks
Languages
Swift 100%