2 ms·
> 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
by 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.