multithreading attempt (failure)
This commit is contained in:
parent
bc5b84d447
commit
2355ced19a
@ -38,6 +38,10 @@ pub struct Validator{
|
|||||||
roblox_cookie:rbx_asset::cookie::CookieContext,
|
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||||
api:api::Context,
|
api:api::Context,
|
||||||
}
|
}
|
||||||
|
pub struct PartialValidator{
|
||||||
|
roblox_cookie:rbx_asset::cookie::CookieContext,
|
||||||
|
api:api::Context,
|
||||||
|
}
|
||||||
|
|
||||||
impl Validator{
|
impl Validator{
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
@ -51,16 +55,27 @@ impl Validator{
|
|||||||
api,
|
api,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub async fn run(mut self){
|
pub async fn run(Self{mut subscriber,roblox_cookie,api}:Self){
|
||||||
while let Some(message)=self.subscriber.next().await{
|
let sem=tokio::sync::Semaphore::new(16);
|
||||||
self.validate_supress_error(message).await
|
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{
|
match self.validate(message).await{
|
||||||
Ok(())=>println!("Validated, hooray!"),
|
Ok(())=>println!("Validated, hooray!"),
|
||||||
Err(e)=>println!("There was an error, oopsie! {e}"),
|
Err(e)=>println!("There was an error, oopsie! {e}"),
|
||||||
}
|
}
|
||||||
|
std::mem::drop(permit);
|
||||||
}
|
}
|
||||||
async fn validate(&self,message:async_nats::Message)->Result<(),ValidateError>{
|
async fn validate(&self,message:async_nats::Message)->Result<(),ValidateError>{
|
||||||
println!("validate {:?}",message);
|
println!("validate {:?}",message);
|
||||||
|
Loading…
Reference in New Issue
Block a user