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 negative result: Uncancelable wrapper that spawns a task #8

Open
sunshowers opened this issue Oct 16, 2023 · 1 comment
Open

Add negative result: Uncancelable wrapper that spawns a task #8

sunshowers opened this issue Oct 16, 2023 · 1 comment

Comments

@sunshowers
Copy link
Collaborator

sunshowers commented Oct 16, 2023

@hawkw and I were discussing a Uncancelable<F: FusedFuture> wrapper which runs a future, and spawns a task with the remaining work if the future is dropped before being completed. It is possible to write that, but it ran into several issues:

  • It's basically equivalent to eagerly spawning a task.
  • It requires the future to be Unpin, so it can be moved out of the Uncancelable future in order to spawn it as a task in the Drop impl. This implies that if the future is an async block, it would need to be eagerly boxed at construction time. So you aren't saving on allocations.
  • All the other typical limitations of spawning tasks apply, such that the future must be Send + 'static.

The one advantage is that it would avoid spawning a task if the wrapper is run to completion, but honestly the added complexity doesn't seem worth it.

We should document this in a "negative results" section in the cancel-safe-futures docs.

@hawkw
Copy link
Member

hawkw commented Oct 16, 2023

here's a half-finished playground where i was trying to get this working: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f373579029e31dcc1a4fb95ed4bb2e2d

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

No branches or pull requests

2 participants