diff --git a/validation/src/validator.rs b/validation/src/validator.rs index 23aebd9..7236ff3 100644 --- a/validation/src/validator.rs +++ b/validation/src/validator.rs @@ -38,6 +38,10 @@ pub struct Validator{ roblox_cookie:rbx_asset::cookie::CookieContext, api:api::Context, } +pub struct PartialValidator{ + roblox_cookie:rbx_asset::cookie::CookieContext, + api:api::Context, +} impl Validator{ pub async fn new( @@ -51,16 +55,27 @@ impl Validator{ api, }) } - pub async fn run(mut self){ - while let Some(message)=self.subscriber.next().await{ - self.validate_supress_error(message).await + pub async fn run(Self{mut subscriber,roblox_cookie,api}:Self){ + let sem=tokio::sync::Semaphore::new(16); + let partial_validator=PartialValidator{ + roblox_cookie, + api, + }; + loop{ + let permit=sem.acquire().await.unwrap(); + if let Some(message)=subscriber.next().await{ + tokio::spawn(partial_validator.validate_supress_error(message,permit)); + } } } - async fn validate_supress_error(&self,message:async_nats::Message){ +} +impl PartialValidator{ + async fn validate_supress_error(&self,message:async_nats::Message,permit:tokio::sync::SemaphorePermit<'_>){ match self.validate(message).await{ Ok(())=>println!("Validated, hooray!"), Err(e)=>println!("There was an error, oopsie! {e}"), } + std::mem::drop(permit); } async fn validate(&self,message:async_nats::Message)->Result<(),ValidateError>{ println!("validate {:?}",message);