swift-server / swift-service-lifecycle

Cleanly startup and shutdown server application, freeing resources in order before exiting.
https://swiftpackageindex.com/swift-server/swift-service-lifecycle/documentation/servicelifecycle
Apache License 2.0
385 stars 37 forks source link

Add async gracefulShutdown function to wait on graceful shutdown trigger #158

Closed gjcairo closed 1 year ago

gjcairo commented 1 year ago

Motivation

Sometimes, it's useful to wait for graceful shutdown to happen before resuming execution on a task.

This can be of particular interest when we don't have anything to do in a Service's run method but want to make sure some cleanup happens on graceful shutdown. In this scenario, we can achieve this by calling await gracefulShutdown() in run(), followed by whatever cleanup we must do.

Modification

This PR adds a new gracefulShutdown() function to the GracefulShutdown suite.

Result

A new gracefulShutdown() method in the GracefulShutdown suite.

FranzBusch commented 1 year ago

@swift-server-bot test this please

FranzBusch commented 1 year ago

@swift-server-bot add to allowlist

FranzBusch commented 1 year ago

@swift-server-bot add to allowlist

FranzBusch commented 1 year ago

@swift-server-bot test this please

gjcairo commented 1 year ago

@swift-server-bot test this please

gjcairo commented 1 year ago

@swift-server-bot test this please