tokio-timer icon indicating copy to clipboard operation
tokio-timer copied to clipboard

how to stop the timer

Open guanqun opened this issue 8 years ago • 1 comments

This seems to be a dumb question, but how can we stop a timer, there's no such "reset()" or "stop" interface.

My code basically looks like this:

    let mut core = ::tokio_core::reactor::Core::new().unwrap();
    let timer = Timer::default();
    let my_timer = timer.interval(std::time::Duration::from_millis(1_000))
        .for_each(|_| {
                      println!("timer triggered");
                      // how can I e.g. remove this my_timer after three triggers?
                      Ok(())
         });

    core.run(my_timer).unwarp();

guanqun avatar Jul 06 '17 07:07 guanqun

Why not timer.interval(xx).take(3).for_each()?

BusyJay avatar Dec 13 '17 13:12 BusyJay