Skip to content

Commit

Permalink
can't await in thread_local
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang committed Dec 15, 2023
1 parent a5011c2 commit 54e5f12
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions async_state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait Counter {
fn __canister_method_inc() {
ic_cdk::setup();
ic_cdk::spawn(async {
let _result = CANISTER.lock().unwrap().inc().await;
let _result = CANISTER.with(|c| c.borrow_mut().inc().await);
ic_cdk::api::call::reply(())
});
}
Expand All @@ -19,15 +19,14 @@ fn __canister_method_inc() {
fn __canister_method_read() {
ic_cdk::setup();
ic_cdk::spawn(async {
let result = CANISTER.lock().unwrap().read();
let result = CANISTER.with(|c| c.borrow().read());
ic_cdk::api::call::reply((result,))
});
}

use once_cell::sync::Lazy;
use std::sync::Mutex;
static CANISTER: Lazy<Mutex<Canister>> = Lazy::new(|| Mutex::new(Default::default()));

thread_local! {
static CANISTER: ::std::cell::RefCell<Canister> = ::std::cell::RefCell::new(Canister::default());
}
// Expand End

#[derive(Default)]
Expand Down

0 comments on commit 54e5f12

Please sign in to comment.