This commit is contained in:
Gregor Reitzenstein 2020-12-07 12:11:07 +01:00
parent c1c34aa703
commit d0fe576d62
2 changed files with 14 additions and 4 deletions

View File

@ -8,7 +8,7 @@ use futures::future::BoxFuture;
use genawaiter::{sync::{Gen, GenBoxed, Co}, GeneratorState}; use genawaiter::{sync::{Gen, GenBoxed, Co}, GeneratorState};
use futures_signals::signal::{Signal, MutableSignalCloned}; use futures_signals::signal::{Signal, Mutable, MutableSignalCloned};
use crate::machine::{Machine, ReturnToken}; use crate::machine::{Machine, ReturnToken};
use crate::db::machine::MachineState; use crate::db::machine::MachineState;
use crate::db::user::{User, UserId, UserData}; use crate::db::user::{User, UserId, UserData};
@ -35,6 +35,13 @@ impl<S: Sensor> Initiator<S> {
sensor: sensor, sensor: sensor,
} }
} }
pub fn wrap(sensor: Box<S>) -> (Mutable<Option<Machine>>, Self) {
let m = Mutable::new(None);
let s = m.signal_cloned();
(m, Self::new(sensor, s))
}
} }
impl<S: Sensor> Future for Initiator<S> { impl<S: Sensor> Future for Initiator<S> {
@ -68,8 +75,9 @@ impl<S: Sensor> Future for Initiator<S> {
} }
} }
pub fn load<S: Sensor>() -> Result<Initiator<S>> { pub fn load() -> Result<(Mutable<Option<Machine>>, Initiator<Dummy>)> {
unimplemented!() let d = Box::new(Dummy::new());
Ok(Initiator::wrap(d))
} }
pub struct Dummy { pub struct Dummy {

View File

@ -135,12 +135,13 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
} else { } else {
//let machines = machine::load(&config)?; //let machines = machine::load(&config)?;
//let initiators = initiator::load(&config)?;
let ex = Executor::new(); let ex = Executor::new();
let m = futures_signals::signal::Mutable::new(crate::db::machine::MachineState::new()); let m = futures_signals::signal::Mutable::new(crate::db::machine::MachineState::new());
let (mut tx, actor) = actor::load()?; let (mut tx, actor) = actor::load()?;
let (mut init_machine, initiator) = initiator::load()?;
// TODO HERE: restore connections between initiators, machines, actors // TODO HERE: restore connections between initiators, machines, actors
// Like so // Like so
@ -150,6 +151,7 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
// Like so // Like so
let t = ex.spawn(actor); let t = ex.spawn(actor);
let t2 = ex.spawn(initiator);
let (signal, shutdown) = async_channel::bounded::<()>(1); let (signal, shutdown) = async_channel::bounded::<()>(1);
easy_parallel::Parallel::new() easy_parallel::Parallel::new()