Skip to content
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

Add withTaskCancellationOrGracefulShutdownHandler #176

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

adam-fowler
Copy link
Member

Execute an operation with a graceful shutdown or task cancellation handler that’s immediately invoked if the current task is shutting down gracefully or has been cancelled.

}
}

func testWithTaskCancellationOrGracefulShutdownHandler_TaskCancellation() async throws {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was quite awkward to construct a test that actually tested cancellation as AsyncStream.next() exits immediately if it is cancelled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need any of the streams here. Just create a LockedValueBox<CheckedContinuation<Void, Never>> and then in the operation closure you create the continuation and store it into the lock and in the handler closure you just resume it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the first stream to ensure the withTaskCancellationOrGracefulShutdownHandler operation actually gets run.

The locked value box would have to be a LockedValueBox<CheckedContinuation<Void, Never>?> and then if I was to be correct I would have to deal with the situation where the cancellation handler gets called before the operation and optional CheckedContinuation is still nil

@FranzBusch FranzBusch merged commit 3a186ea into main Feb 19, 2024
6 checks passed
@FranzBusch FranzBusch deleted the taskcancellation_or_gracefulshutdown branch February 19, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants