Rust/wasm32 : spawn future with kill on drop

I need this to work on Rust/wasm32.

We have

f: Future<Output = ()>

I want to do

let handle = magic_func(f); // spawns a async for f

with the property that when handle gets dropped, the (currently parked) f gets killed .

Is this possible to do safely in Rust ?

Sure it is.

Its just a case of wrapping your future in a futures::future::Abortable and making a RAII guard that triggers the associated futures::AbortHandle on drop.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.