4 ms·
Explicit cancellation can be had just by.. dropping the Future. Its great to have a Rust expert to turn up in a Go thread to educate the masses. I have one qu
by papaf 6y ago
Explicit cancellation can be had just by.. dropping the Future.
Its great to have a Rust expert to turn up in a Go thread to educate the masses.
I have one question from the cheap seats though. How do you drop the Future, with a decision made at runtime, given that lifetimes are part of the type system?
Thanks for your help.
- Nullabillity 6y agoIt's not very useful to borrow futures, so that tends not to be an issue in practice.
- msbarnett 6y ago> I have one question from the cheap seats though. How do you drop the Future, with a decision made at runtime, given that lifetimes are part of the type system? Trivially, something like let future = some_long_running_async_function(); let timer = delay(Duration::from_millis(10000)); select! { result = future => { // handle result of future completing successfully }, _ = timer => { // future missed the deadline, drop it, terminating execution. std::mem::drop(future); } } If this were wrapped in a function you could also just return out of the timer branch and let the future naturally drop as the stack popped.