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

Allow better customization of cancellation behaviour #487

Open
mdickinson opened this issue Sep 22, 2021 · 2 comments
Open

Allow better customization of cancellation behaviour #487

mdickinson opened this issue Sep 22, 2021 · 2 comments
Labels
type: enhancement New feature or request

Comments

@mdickinson
Copy link
Member

For the built-in task types, the current cancellation behaviour is that no further messages are received from the background task after cancellation. While this keeps the model simple, it's (a) rather brutal, and (b) not that well suited to cases where the background task being performed has side-effects.

Historical background: Traits Futures emerged from use-cases involving pushing calculations (pure functions, with a collection of inputs and a collection of computed outputs) to the background; in those cases, it make some sense for cancellation to mean "I'm no longer interested in this computation; don't tell me anything more about it".

However, the library is now being used for background tasks that are primarily there for their side-effects - e.g., uploading or downloading a file. In that situation, it would be useful to be able to:

  • On cancellation, report the final status of the job (e.g., the number of files that were uploaded prior to cancellation, or the list of processed ids, or ...)
  • Revert unwanted changes: e.g., roll back the completed portion of an incomplete transaction

The second use-case here should be easily supported by allowing the developer to catch the TaskCancelled exception; for the first, the ABANDONED message type could be adjusted to allow sending a value.

Related: #437. (See also #448.)

@mdickinson mdickinson added the type: enhancement New feature or request label Sep 22, 2021
@mdickinson
Copy link
Member Author

We should also look into making it easier to choose whether to continue to receive messages from the background task post-cancellation.

@mdickinson
Copy link
Member Author

  • Revert unwanted changes: e.g., roll back the completed portion of an incomplete transaction

This one's a little tricky, and subject to potential race conditions: the background task may not always get a chance to intercept the cancellation request, since the task might have completed (but with the completion message not having yet been received by the foreground) before the user cancels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant