You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some reason the following code hangs. I sense that I might be doing something fundamentally wrong and that I should probably be storing the future inside the struct?
Repro:
use std::future::Future;use std::task::{Context,Poll};use std::pin::Pin;#[derive(Clone,Debug)]pubstructThing;implFutureforThing{typeOutput = ();fnpoll(self:Pin<&mutSelf>,ctx:&mutContext) -> Poll<Self::Output>{letmut fut = Box::pin(reqwest::get("https://httpstat.us/200"));let _res = match fut.as_mut().poll(ctx){Poll::Ready(ret) => ret,Poll::Pending => returnPoll::Pending,};// do something with the resultPoll::Ready(())}}#[cfg(test)]mod tests {usesuper::*;#[tokio::test]asyncfntest_thing(){let _logger = env_logger::init();let thing = Thing;// hangs herelet ret = thing.await;dbg!(ret);}}
Running it with RUST_LOG = hyper results in the following logs:
If you drop the future after polling, it will cancel and never wake up the task again. You need to store it in your custom future. You might find it easier to just use an async fn.
For some reason the following code hangs. I sense that I might be doing something fundamentally wrong and that I should probably be storing the future inside the struct?
Repro:
Running it with
RUST_LOG = hyper
results in the following logs:The text was updated successfully, but these errors were encountered: