Skip to content

Provide a CancelOnGracefulShutdownService #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fabianfett opened this issue Oct 31, 2023 · 3 comments
Open

Provide a CancelOnGracefulShutdownService #163

fabianfett opened this issue Oct 31, 2023 · 3 comments
Labels
good first issue Good for newcomers

Comments

@fabianfett
Copy link
Member

If an adopter already has a reference type that implements a run() method it is currently impossible to support ServiceLifecycle, even though the implementation works easily:

extension MyExistingService: Service {}

The reason for this is, that ServiceLifecycle uses gracefulShutdown to signal shutdown instead of Task cancellation. That is the correct call. However it is impossible to add gracefulShutdown support to object that already expose a run() method. That's why im proposing that ServiceLifecycle offers a CancelOnGracefulShutdownService<Underlying: Service>.

@FranzBusch FranzBusch added the good first issue Good for newcomers label Nov 17, 2023
@adam-fowler
Copy link
Member

adam-fowler commented Jan 9, 2024

Conforming MyExistingService to Service doesn't seem correct as it doesn't support graceful shutdown.
Perhaps we need another protocol CancellableService for a Service that is only cancellable. Then your service could look like

protocol CancellableService {
    func run() async throws
}

struct CancelOnGracefulShutdownService<S: CancellableService> {
    @usableFromInline
    let service: S

    @inlinable
    func run() async throws {
        try await CancelOnGracefulShutdown {
            try await self.service.run()
        }
    }
}

@supersonicbyte
Copy link

hey folks! Can I try to tackle this one?

@FranzBusch
Copy link
Contributor

I am not yet sure we need this. In one of the latest releases we introduced support to escalate graceful shutdown to cancellation. This should help with services that don't support graceful shutdown right now.

I would like to wait for more user reports here if we really need such a new protocol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants