mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 14:57:56 +01:00
Async actor runs now
This commit is contained in:
parent
f4148d398f
commit
8e3b8834c0
@ -26,7 +26,7 @@ pub struct Actor<S: Signal> {
|
||||
inner: Option<S>,
|
||||
|
||||
actuator: Box<dyn Actuator + Send + Sync>,
|
||||
future: Option<Box<dyn Future<Output=()> + Unpin + Send>>,
|
||||
future: Option<BoxFuture<'static, ()>>,
|
||||
}
|
||||
|
||||
impl<S: Signal + Unpin> Actor<S> {
|
||||
@ -80,7 +80,7 @@ impl<S: Signal<Item=MachineState> + Unpin> Future for Actor<S> {
|
||||
}
|
||||
},
|
||||
Some(Poll::Ready(Some(state))) => {
|
||||
this.actuator.apply(state);
|
||||
this.future.replace(this.actuator.apply(state));
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
@ -151,11 +151,16 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
|
||||
// TODO HERE: Spawn all actors & inits
|
||||
|
||||
// Like so
|
||||
ex.spawn(actor);
|
||||
let t = ex.spawn(actor);
|
||||
|
||||
let (signal, shutdown) = async_channel::bounded::<()>(1);
|
||||
easy_parallel::Parallel::new()
|
||||
.each(0..4, |_| smol::block_on(ex.run(shutdown.recv())));
|
||||
.each(0..4, |_| smol::block_on(ex.run(shutdown.recv())))
|
||||
.run();
|
||||
|
||||
smol::block_on(t);
|
||||
|
||||
|
||||
|
||||
let db = db::Databases::new(&log, &config)?;
|
||||
// TODO: Spawn api connections on their own (non-main) thread, use the main thread to
|
||||
|
@ -6,6 +6,7 @@ use smol::lock::RwLock;
|
||||
use std::pin::Pin;
|
||||
use futures::ready;
|
||||
use futures::prelude::*;
|
||||
use futures::future::BoxFuture;
|
||||
use futures::channel::mpsc;
|
||||
use futures::task::{Context, Poll, Spawn};
|
||||
use futures_signals::signal::Signal;
|
||||
@ -15,13 +16,14 @@ use crate::db::machine::MachineState;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub trait Actuator {
|
||||
fn apply(&mut self, state: MachineState);
|
||||
fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()>;
|
||||
}
|
||||
|
||||
pub struct Dummy;
|
||||
|
||||
impl Actuator for Dummy {
|
||||
fn apply(&mut self, state: MachineState) {
|
||||
fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()> {
|
||||
println!("New state for dummy actuator: {:?}", state);
|
||||
Box::pin(smol::future::ready(()))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user