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

Abortable Task #2496

Merged
merged 2 commits into from
Jul 10, 2024
Merged

Abortable Task #2496

merged 2 commits into from
Jul 10, 2024

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented Jul 10, 2024

This PR introduces the Task::abortable method, which returns a task::Handle that can be used to easily cancel a Task that has already been handled to the runtime.

This is useful for long-running tasks that are not well-suited to become subscriptions (i.e. may eventually finish on their own) and that may need to be canceled by the user, like downloading a file (yes, this means our download_progress example is outdated).

@hecrj hecrj added feature New feature or request addition labels Jul 10, 2024
@hecrj hecrj added this to the 0.13 milestone Jul 10, 2024
@JL710
Copy link
Contributor

JL710 commented Jul 10, 2024

What would the key difference between Tasks and Subscriptions be?

@hecrj
Copy link
Member Author

hecrj commented Jul 10, 2024

@JL710 The main difference is the guarantees they provide. From an application's perspective:

  • A Task is some workload that may eventually finish on its own, independently of the application state.

  • A Subscription is a request to listen to "something" that must always be there for the whole lifetime of the application (like a webserver connection, the iced runtime, or just time itself). A Subscription cannot end on its own; only the application can eventually unsubscribe from it.

Therefore, all subscriptions are infinite and abortable by design; and aborting can be done declaratively—the same way that widgets can be shown and hidden in view.

@hecrj hecrj merged commit 70f44a6 into master Jul 10, 2024
24 checks passed
@hecrj hecrj deleted the abortable-tasks branch July 10, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants