1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

Fix deadlock in casbin example (#471)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Christian Beier 2022-01-19 20:49:57 +01:00 committed by GitHub
parent 0c316ec330
commit 1cc73366c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

1
Cargo.lock generated
View File

@ -57,6 +57,7 @@ dependencies = [
"loge",
"rhai",
"rhai_codegen",
"tokio 0.2.25",
]
[[package]]

View File

@ -13,3 +13,4 @@ casbin = "=2.0.5"
rhai = "=0.19.14"
rhai_codegen = "=0.3.3"
loge = {version = "0.4", default-features = false, features = ["colored", "chrono"]}
tokio = { version = "0.2.22", features = ["sync"] }

View File

@ -1,6 +1,6 @@
use casbin::{CoreApi, DefaultModel, Enforcer, FileAdapter, RbacApi};
use std::io;
use std::sync::RwLock;
use tokio::sync::RwLock;
use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer};
@ -9,7 +9,7 @@ async fn success(
enforcer: web::Data<RwLock<Enforcer>>,
req: HttpRequest,
) -> HttpResponse {
let mut e = enforcer.write().unwrap();
let mut e = enforcer.write().await;
println!("{:?}", req);
assert_eq!(vec!["data2_admin"], e.get_roles_for_user("alice", None));
@ -17,7 +17,7 @@ async fn success(
}
async fn fail(enforcer: web::Data<RwLock<Enforcer>>, req: HttpRequest) -> HttpResponse {
let mut e = enforcer.write().unwrap();
let mut e = enforcer.write().await;
println!("{:?}", req);
assert_eq!(vec!["data1_admin"], e.get_roles_for_user("alice", None));