Skip to content

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

@sunshowers

Description

@sunshowers

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions