Struct rotor::LoopCreator [] [src]

pub struct LoopCreator<M: Machine> {
    // some 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()

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()

The the guide for more information.

Methods

impl<M: Machine> LoopCreator<M>

fn new(cfg: &Config) -> Result<LoopCreator<M>, Error>

fn add_machine_with<F>(&mut self, fun: F) -> Result<(), SpawnError<()>> where F: FnOnce(&mut EarlyScope) -> Response<M, Void>

fn instantiate(self, context: M::Context) -> LoopInstance<M>

fn run(self, context: M::Context) -> Result<(), Error>