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
396 stars 38 forks source link

Make `CancellationWaiter` public #169

Closed adam-fowler closed 8 months ago

adam-fowler commented 10 months ago

I've implemented a version (I forgot to add cancellation support as well as graceful shutdown), I know other people have done the same as well. Should we be just using the one that is already written here

ktoso commented 10 months ago

Sounds like a good idea, though it should be renamed probably since it also waits for graceful shutdown?

Also, worth lifting such type into concurrency library perhaps?

adam-fowler commented 10 months ago

Also, worth lifting such type into concurrency library perhaps?

You'd have to lift the whole graceful shutdown system into the Concurrency library then (which isn't necessarily a bad thing).

ktoso commented 10 months ago

I meant a form of this without the graceful shutdown, "wait for cancellation" minor trick but might be nice to lift eventually. I often feel we're missing small convenient things like that

adam-fowler commented 8 months ago

@FranzBusch ?

FranzBusch commented 8 months ago

This is actually already publicly exposed. Just use try await gracefulShutdown() which will wait for either cancellation or graceful shutdown. In case of cancellation you will get a CancellationError thrown.