Function glib::source::timeout_add [] [src]

pub fn timeout_add<F>(interval: u32, func: F) -> u32 where F: FnMut() -> Continue + 'static

Sets a function to be called at regular intervals, with the default priority, PRIORITY_DEFAULT.

The function is called repeatedly until it returns Continue(false), at which point the timeout is automatically destroyed and the function will not be called again. The first call to the function will be at the end of the first interval .

Note that timeout functions may be delayed, due to the processing of other event sources. Thus they should not be relied on for precise timing. After each call to the timeout function, the time of the next timeout is recalculated based on the current time and the given interval (it does not try to 'catch up' time lost in delays).

If you want to have a timer in the "seconds" range and do not care about the exact time of the first call of the timer, use the timeout_add_seconds() function; this function allows for more optimizations and more efficient system power usage.

The interval given is in terms of monotonic time, not wall clock time. See g_get_monotonic_time() in glib documentation.

Examples

timeout_add(3000, || {
    println!("This prints once every 3 seconds");
    Continue(true)
});