Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with tokio #50

Open
D1plo1d opened this issue Aug 23, 2019 · 1 comment
Open

How to use with tokio #50

D1plo1d opened this issue Aug 23, 2019 · 1 comment

Comments

@D1plo1d
Copy link

D1plo1d commented Aug 23, 2019

I see in the example that you mention state_machine_future should work with Tokio but I'm not sure how (I am new to rust). Would it be possible to add a complete tokio example to the docs? What am I doing wrong here?

use tokio::timer::Delay;
use std::time::{Duration, Instant};

impl PollMyStateMachine for MyStateMachine {
    fn poll_start<'a>(
        start: &'a mut RentToOwn<'a, Start>
    ) -> Poll<AfterStart, std::io::Error> {
        println!("STARTING");
        let when = Instant::now() + Duration::from_millis(100);
        let mut task = Delay::new(when)
            .map_err(|e| panic!("delay errored; err={:?}", e))
            .and_then(|_| {
                println!("Hello world!");
                Ok(ShutDown(()))
            })
            .map_err(|e| std::io::Error::new(ErrorKind::Other, "oh no!"));
        let next_state = try_ready!(task.poll());

        transition!(next_state)
    }
}
@bkchr
Copy link
Collaborator

bkchr commented Aug 28, 2019

Tokio executes Futures and the state machine is a Future.

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

No branches or pull requests

2 participants