Change the execution order of chain and race guards. #614

This commit is contained in:
Sunli 2021-09-24 10:30:46 +08:00
parent 923ed490de
commit 4740579ec9
2 changed files with 6 additions and 4 deletions

View File

@ -225,7 +225,7 @@ pub fn generate_guards(
guards = guard;
} else {
guards =
Some(quote! { #crate_name::guard::GuardExt::and(#guard, #guards) });
Some(quote! { #crate_name::guard::GuardExt::and(#guards, #guard) });
}
}
}
@ -245,7 +245,7 @@ pub fn generate_guards(
guards = guard;
} else {
guards =
Some(quote! { #crate_name::guard::GuardExt::or(#guard, #guards) });
Some(quote! { #crate_name::guard::GuardExt::or(#guards, #guard) });
}
}
}

View File

@ -45,7 +45,9 @@ pub struct Or<A: Guard, B: Guard>(A, B);
#[async_trait::async_trait]
impl<A: Guard + Send + Sync, B: Guard + Send + Sync> Guard for Or<A, B> {
async fn check(&self, ctx: &Context<'_>) -> Result<()> {
let second_result = self.1.check(ctx).await;
self.0.check(ctx).await.or(second_result)
if self.0.check(ctx).await.is_ok() {
return Ok(());
}
self.1.check(ctx).await
}
}