Closed zyctree closed 5 years ago
The problem may be about runtime::enter
,
let (tx, rx) = futures::channel::oneshot::channel();
let fut = async move {
let t = fut.await;
let _ = tx.send(t);
};
in this case, fut
is never ready, but tx
dropped, and rx
got a Cancel
one solution is to clone the waker
to Pending
, like
struct EndlessPending(Option<Waker>);
impl Future for EndlessPending {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
self.as_mut().0 = Some(cx.waker().clone());
Poll::Pending
}
}
The following codes will panick,
it outputs
it is the case, where all my codes are running in
runtime::spawn
, so i needfutures::future::pending()
to not exit the whole programhowever, i tried it in
runtime_tokio
, it didn't panickit succeeds to loop infinitely.