Currently in Wasmtime with component-model-async when a host function is cancelled the future representing that host function is simply dropped. I believe that the future gets a single final poll to produce a result before being dropped, but fundamentally Wasmtime doesn't provide embedders a means by which to gracefully handle the cancellation signal. This means that it's not easy or possible to impelement a sort of "atomic cancellation" in Wasmtime today where upon receiving cancellation some operation may already be complete but it is unable to communicate that. This is inspired by discussion here w.r.t cancelling UDP send operations.
Some possible shapes of a solution here are:
- Instead of returning a return value, hosts could be provided an object through which the return value is transmitted. This models
task.return more closely and bindings generation could paper over the differences here. This would enable hosts to at least provide a return value in a Drop implementation.
- Hosts could be provided a sort of
CancellationToken which has helper methods/etc to test/await it. Wasmtime would then not actually drop the future at all, but it would instead set the CancellationToken and continue polling as usual. It'd be up to embedders to drop futures, for example.
Currently in Wasmtime with component-model-async when a host function is cancelled the future representing that host function is simply dropped. I believe that the future gets a single final
pollto produce a result before being dropped, but fundamentally Wasmtime doesn't provide embedders a means by which to gracefully handle the cancellation signal. This means that it's not easy or possible to impelement a sort of "atomic cancellation" in Wasmtime today where upon receiving cancellation some operation may already be complete but it is unable to communicate that. This is inspired by discussion here w.r.t cancelling UDPsendoperations.Some possible shapes of a solution here are:
task.returnmore closely and bindings generation could paper over the differences here. This would enable hosts to at least provide a return value in aDropimplementation.CancellationTokenwhich has helper methods/etc to test/await it. Wasmtime would then not actually drop the future at all, but it would instead set theCancellationTokenand continue polling as usual. It'd be up to embedders to drop futures, for example.