Add a processor API to the coordinator

This commit is contained in:
Luke Parker
2023-04-17 02:10:33 -04:00
parent 595cd6d404
commit 92a868e574
3 changed files with 139 additions and 69 deletions

View File

@@ -0,0 +1,41 @@
use std::{
sync::{Arc, RwLock},
collections::VecDeque,
};
use processor_messages::{ProcessorMessage, CoordinatorMessage};
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Message {
pub id: u64,
pub msg: ProcessorMessage,
}
#[async_trait::async_trait]
pub trait Processor: 'static + Send + Sync {
async fn send(&mut self, msg: CoordinatorMessage);
async fn recv(&mut self) -> Message;
async fn ack(&mut self, msg: Message);
}
// TODO: Move this to tests
pub struct MemProcessor(Arc<RwLock<VecDeque<Message>>>);
impl MemProcessor {
#[allow(clippy::new_without_default)]
pub fn new() -> MemProcessor {
MemProcessor(Arc::new(RwLock::new(VecDeque::new())))
}
}
#[async_trait::async_trait]
impl Processor for MemProcessor {
async fn send(&mut self, _: CoordinatorMessage) {
todo!()
}
async fn recv(&mut self) -> Message {
todo!()
}
async fn ack(&mut self, _: Message) {
todo!()
}
}