Skip to content

Futures should be individually cancellable #520

Open
@kainino0x

Description

@kainino0x

Futures can currently be cancelled only by dropping the instance. It would be useful to be able cancel them individually.

As an example, if you write a C++ RAII wrapper around a WGPUFuture (say, myapp::WebGPUFuture<wgpu::ComputePipeline>) and you drop it, there's no way to ensure the callback gets called except to wait for the future. If we had a way to cancel futures like void wgpuInstanceCancelFuture(WGPUFuture)1, you could do that instead - basically, call the callback immediately and ignore/abort any ongoing work.

Right now we already have the InstanceDropped status, I think we could genericize this to Canceled/Cancelled2 and use it for this too.

Footnotes

  1. This function could have a return value indicating whether it actually got canceled, though it seems probably not necessary because you'll get the status via the callback.

  2. though I dislike this word because its spelling is ambiguous, similar to adapter vs adaptor

Metadata

Metadata

Assignees

No one assigned

    Labels

    asyncAsynchronous operations and callbacksnon-breakingDoes not require a breaking change (that would block V1.0)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

        翻译: