2020-12-01 10:21:39 +01:00
|
|
|
use std::pin::Pin;
|
|
|
|
use std::task::{Poll, Context};
|
|
|
|
use std::sync::Arc;
|
2020-12-01 09:44:18 +01:00
|
|
|
use std::future::Future;
|
|
|
|
|
2020-12-01 10:21:39 +01:00
|
|
|
use smol::Executor;
|
|
|
|
|
|
|
|
use futures::{future::BoxFuture, Stream, StreamExt};
|
2020-12-01 09:44:18 +01:00
|
|
|
use futures_signals::signal::Signal;
|
|
|
|
|
|
|
|
use crate::db::machine::MachineState;
|
|
|
|
use crate::registries::Actuator;
|
|
|
|
use crate::config::Settings;
|
|
|
|
use crate::error::Result;
|
|
|
|
|
|
|
|
pub struct Actor {
|
2020-12-01 10:21:39 +01:00
|
|
|
inner: Box<dyn Actuator + Unpin>,
|
|
|
|
f: Option<BoxFuture<'static, ()>>
|
2020-12-01 09:44:18 +01:00
|
|
|
}
|
|
|
|
|
2020-12-01 10:21:39 +01:00
|
|
|
unsafe impl Send for Actor {}
|
|
|
|
|
2020-12-01 09:44:18 +01:00
|
|
|
impl Actor {
|
2020-12-01 10:21:39 +01:00
|
|
|
pub fn new(inner: Box<dyn Actuator + Unpin>) -> Self {
|
|
|
|
Self {
|
|
|
|
inner: inner,
|
|
|
|
f: None,
|
|
|
|
}
|
2020-12-01 09:44:18 +01:00
|
|
|
}
|
2020-12-01 10:21:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Future for Actor {
|
|
|
|
type Output = ();
|
|
|
|
|
|
|
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
|
|
|
let mut this = &mut *self;
|
|
|
|
|
|
|
|
// If we have a future at the moment, poll it
|
|
|
|
if let Some(mut f) = this.f.take() {
|
|
|
|
if Future::poll(Pin::new(&mut f), cx).is_pending() {
|
|
|
|
this.f.replace(f);
|
|
|
|
}
|
|
|
|
}
|
2020-12-01 09:44:18 +01:00
|
|
|
|
2020-12-01 10:21:39 +01:00
|
|
|
match Stream::poll_next(Pin::new(&mut this.inner), cx) {
|
|
|
|
Poll::Ready(None) => Poll::Ready(()),
|
|
|
|
Poll::Ready(Some(f)) => {
|
|
|
|
this.f.replace(f);
|
|
|
|
Poll::Pending
|
|
|
|
}
|
|
|
|
Poll::Pending => Poll::Pending
|
|
|
|
}
|
2020-12-01 09:44:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn load(config: &Settings) -> Result<Vec<Actor>> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|