the natsy

This commit is contained in:
Quaternions 2024-12-02 22:09:01 -08:00
parent 7375842089
commit c7f3cdc0d6
3 changed files with 82 additions and 2 deletions

View File

@ -1,5 +1,23 @@
mod publisher;
mod validator;
#[tokio::main]
async fn main(){
#[allow(dead_code)]
#[derive(Debug)]
enum StartupError{
Connect(async_nats::ConnectError),
Subscribe(async_nats::SubscribeError),
}
#[tokio::main]
async fn main()->Result<(),StartupError>{
let nasty=async_nats::connect("nats").await.map_err(StartupError::Connect)?;
let (publisher,validator)=tokio::try_join!(
publisher::Publisher::new(nasty.clone()),
validator::Validator::new(nasty)
).map_err(StartupError::Subscribe)?;
// publisher thread
tokio::spawn(publisher.run());
// run validator on the main thread indefinitely
validator.run().await;
Ok(())
}

View File

@ -0,0 +1,25 @@
use futures::StreamExt;
enum PublishError{
}
pub struct Publisher{
nats:async_nats::Client,
subscriber:async_nats::Subscriber,
}
impl Publisher{
pub async fn new(nats:async_nats::Client)->Result<Self,async_nats::SubscribeError>{
Ok(Self{
subscriber:nats.subscribe("publish").await?,
nats,
})
}
pub async fn run(mut self){
while let Some(message)=self.subscriber.next().await{
self.publish(message).await
}
}
async fn publish(&self,message:async_nats::Message){
println!("publish {:?}",message);
}
}

View File

@ -0,0 +1,37 @@
use futures::StreamExt;
use rbx_dom_weak::WeakDom;
enum Valid{
Untouched(WeakDom),
Modified(WeakDom),
}
enum ValidateError{
}
pub struct Validator{
nats:async_nats::Client,
subscriber:async_nats::Subscriber,
}
impl Validator{
pub async fn new(nats:async_nats::Client)->Result<Self,async_nats::SubscribeError>{
Ok(Self{
subscriber:nats.subscribe("validate").await?,
nats,
})
}
pub async fn run(mut self){
while let Some(message)=self.subscriber.next().await{
self.validate(message).await
}
}
async fn validate(&self,message:async_nats::Message){
println!("validate {:?}",message);
// download map
// validate map
// validate(dom)
// reply with validity
// Ok(Valid::Untouched(dom))
}
}