1#[macro_use(rotor_compose)] extern crate rotor;
2extern crate rotor_tools;
3
4use std::time::{Duration};
5
6use rotor::{Loop, Config, Scope, Response, Void};
7use rotor_tools::timer::{IntervalFunc, interval_func};
8use rotor_tools::loop_ext::LoopInstanceExt;
9
10#[derive(PartialEq, Eq)]
11struct Dummy;
12
13struct Context;
14
15rotor_compose!(enum Fsm/Seed<Context> {
16 Timer(IntervalFunc<Context>),
17});
18
19fn 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}
27
28fn main() {
29 let loop_creator = Loop::new(&Config::new()).unwrap();
30 let mut loop_inst = loop_creator.instantiate(Context);
31 let value: Dummy = loop_inst.add_and_fetch(Fsm::Timer, |scope| {
32 create_pair(scope)
33 }).unwrap();
34 assert!(value == Dummy);
35 loop_inst.run().unwrap();
36}