Problem in creating tokio timer with long interval


#1

Hello All,

I am trying to create a tokio-timer with a long interval around 600seconds.
Following is the sample code.

let mut core = Core::new().unwrap();
let duration = Duration::new(410, 0);
println!("duration in secs: {}", duration.as_secs());
let wakeup_interval = Timer::default().interval(duration);
let timer = wakeup_interval.for_each(move|()| {
        println!("Timer expired");
        Ok(())
    });

let timer_future = timer.map(|_| {
		println!("Timer run success");
		()
	}).map_err(|err| {
		println!("Failed to run timer, reason:: {:?}", err);
		()
	});

core.run(timer_future);

The above code works fine(Timer expires repeatedly in the given interval), if the duration is lesser than or equal to 409 seconds.
When the duration is on or above 410 seconds, it exits with following error:

Failed to run timer, reason:: TooLong

I’m confused with the above behavior. Looks like there is some limitation on the input duration for the timer.
Is it possible to increase this limit to higher number?

Any help on this would be highly appreciated.
Thanks in advance!!!


#2

https://docs.rs/tokio-timer-plus/0.1.3/tokio_timer/struct.Builder.html#method.max_timeout controls the maximum duration allowed - a duration greater than that returns that error you’re seeing. You can see that the default is 4096 (slots) * 100ms (tick_duration), which is right where you’re triggering this error.


#3

Thank you for the inputs. Using Builder seems to be solving the problem.

Code with following changes works fine.

let duration = Duration::new(410, 0);
let builder = tokio_timer::wheel().max_timeout(duration);
let wakeup_interval = builder.build().interval(duration);