Skip to main content

interval_func

Function interval_func 

Source
pub fn interval_func<C, F>(
    scope: &mut Scope<'_, C>,
    interval: Duration,
    fun: F,
) -> Response<IntervalFunc<C>, Void>
where F: FnMut(&mut Scope<'_, C>) + 'static + Send,
Expand description

A helper function to create intervals from closures

Examples found in repository?
examples/create.rs (lines 23-25)
20fn create_pair<C>(scope: &mut Scope<C>)
21    -> Response<(IntervalFunc<C>, Dummy), Void>
22{
23    interval_func(scope, Duration::new(1, 0), |_| {
24        println!("Second passed");
25    }).wrap(|fsm| (fsm, Dummy))
26}
More examples
Hide additional examples
examples/interval_func.rs (lines 14-16)
10fn main() {
11    let loop_creator = Loop::new(&Config::new()).unwrap();
12    let mut loop_inst = loop_creator.instantiate(());
13    loop_inst.add_machine_with(|scope| {
14        interval_func(scope, Duration::new(1, 0), |_| {
15            println!("Second passed");
16        })
17    }).unwrap();
18    loop_inst.run().unwrap();
19}