Hi there,
I actually have a usecase for futures::pending()
for something that may or may not expire on its own.
So I select!()
against two futures and the (possibly eternal) timeout like this:
let sleep = async {
if let Some(timeout_before_close) = timeout_before_close {
async_std::task::sleep(timeout_before_close).await;
} else {
pending::<()>().await;
}
};
// phase 2: wait for user input (action or close) or expiration
let (reason, action) = select! {
action = action_rx.recv().fuse() => {
log::trace!("close from action");
(CloseReason::CloseAction, action.ok())
}
reason = close_rx.recv().fuse() => {
log::trace!("close from user");
(reason.unwrap_or(CloseReason::Expired), None)
}
_ = sleep.fuse() => {
log::trace!("close from expire after {timeout_before_close:?}", );
(CloseReason::Expired, None)
}
};
all of this runs inside a task, the handle of which I just drop.
my concern now:
does select!()
clean up the pending future if either close_rx
or action_rx
resolve or will this leak?
Thank you