Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Cannot call poll once value is consumed #47

Closed
jedisct1 opened this issue Dec 22, 2017 · 3 comments
Closed

Cannot call poll once value is consumed #47

jedisct1 opened this issue Dec 22, 2017 · 3 comments

Comments

@jedisct1
Copy link

jedisct1 commented Dec 22, 2017

The cannot call poll once value is consumed actually comes from tokio-timer, but I can't explain this behavior:

#![feature(proc_macro, conservative_impl_trait, generators)]
extern crate futures_await as futures;
extern crate tokio_core;
extern crate tokio_timer;
use std::time::Duration;
use tokio_core::reactor::Core;
use futures::prelude::*;

#[async]
fn ola(lv: u32) -> Result<u32, String> {
    let wheel = tokio_timer::wheel().build();
    let timer = wheel.sleep(Duration::new(5, 0));
    let _ = await!(timer);
    println!("ola");
    Ok(lv)
}

#[async]
fn grr() -> Result<u32, ()> {
    let wheel = tokio_timer::wheel().build();
    let ft = ola(42).map_err(|_| ());
    let timer = wheel.timeout(ft, Duration::new(10, 0));
    await!(timer)
}

fn main() {
    let mut core = Core::new().unwrap();
    core.run(grr()).unwrap();
}
thread 'main' panicked at 'cannot call poll once value is consumed'

(fired from await!(timer) in the grr() function).

Just swapping two lines, i.e. replacing:

    let wheel = tokio_timer::wheel().build();
    let ft = ola(42).map_err(|_| ());
    let timer = wheel.timeout(ft, Duration::new(10, 0));

with

    let ft = ola(42).map_err(|_| ());
    let wheel = tokio_timer::wheel().build();
    let timer = wheel.timeout(ft, Duration::new(10, 0));

Makes the panic() go away and the executable work as expected.

How is that possible? Is it a bug in futures-await?

@alexcrichton
Copy link
Owner

Thanks for the report! This looks like a bug in tokio-time, though, so I'm going to close this. You may wish to report this upstream?

@jedisct1
Copy link
Author

I will!

But note that it only happens when using await. The same code returning Futures without using futures-await works fine.

@alexcrichton
Copy link
Owner

It may be that the polling pattern changes? I'm not so sure myself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants