Struct rotor::Loop [] [src]

pub struct Loop<M: Machine> { /* fields omitted */ }

An object that is used to construct a loop

The purpose of the object is to shorten the boilerplate to create an event loop.

The second purpose is to create the loop and state machines before Context is initialized. This is useful when you want to put Notifier objects of state machines into the context.

You can create a loop either right away:

use rotor::{Loop, Config};

let mut lc = Loop::new(&Config::new()).unwrap();
loop_creator.add_machine_with(|scope| {
    // The scope here is the `EarlyScope` (no context)
    Ok(CreateMachine(x))
}).unwrap();
assert!(conn.is_ok());
lc.run(context).unwrap()Run

Or if you can create it in two stages:

let lc = Loop::new(&Config::new()).unwrap();
loop_creator.add_machine_with(|scope| {
    // The scope here is the `EarlyScope`
    Ok(StateMachine1(scope))
}).unwrap();
let mut inst = lc.instantiate(context);
loop_creator.add_machine_with(|scope| {
    // The scope here is the real `Scope<C>`
    Ok(StateMachine2(scope))
}).unwrap();
inst.run().unwrap()Run

The the guide for more information.

Methods

impl<M: Machine> LoopCreator<M>
[src]