Skip to content

Commit 85d1733

Browse files
committed
make POLLED_FORBIDDEN_THING thread-local
1 parent 951888f commit 85d1733

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/factory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use futures_util::{
44
future::{self, Either},
55
pin_mut, FutureExt,
66
};
7-
use std::{future::Future, marker::PhantomData, sync::atomic::Ordering};
7+
use std::{future::Future, marker::PhantomData};
88
use web_sys::{
99
js_sys::{self, Function},
1010
wasm_bindgen::{closure::Closure, JsCast, JsValue},
@@ -145,7 +145,7 @@ impl<Err: 'static> Factory<Err> {
145145
pin_mut!(completion_fut);
146146

147147
let res = future::select(upgrade_rx, completion_fut).await;
148-
if unsafe_jar::POLLED_FORBIDDEN_THING.load(Ordering::Relaxed) {
148+
if unsafe_jar::POLLED_FORBIDDEN_THING.get() {
149149
panic!("Transaction blocked without any request under way");
150150
}
151151

src/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
};
55
use futures_channel::oneshot;
66
use futures_util::future::{self, Either};
7-
use std::{future::Future, marker::PhantomData, sync::atomic::Ordering};
7+
use std::{future::Future, marker::PhantomData};
88
use web_sys::{
99
wasm_bindgen::{JsCast, JsValue},
1010
IdbDatabase, IdbRequest, IdbTransaction, IdbTransactionMode,
@@ -132,7 +132,7 @@ impl<Err> TransactionBuilder<Err> {
132132
};
133133
unsafe_jar::run(t, fut);
134134
let res = rx.await;
135-
if unsafe_jar::POLLED_FORBIDDEN_THING.load(Ordering::Relaxed) {
135+
if unsafe_jar::POLLED_FORBIDDEN_THING.get() {
136136
panic!("Transaction blocked without any request under way");
137137
}
138138
res.expect("Transaction never completed")

src/transaction/unsafe_jar.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::{
1010
future::Future,
1111
pin::Pin,
1212
rc::Rc,
13-
sync::atomic::{AtomicBool, Ordering},
1413
task::{Context, Poll},
1514
};
1615
use web_sys::{
@@ -28,7 +27,7 @@ struct State {
2827
}
2928

3029
scoped_thread_local!(static CURRENT: State);
31-
pub(crate) static POLLED_FORBIDDEN_THING: AtomicBool = AtomicBool::new(false);
30+
thread_local!(pub(crate) static POLLED_FORBIDDEN_THING: Cell<bool> = Cell::new(false));
3231

3332
fn poll_it(state: &State) {
3433
CURRENT.set(&state, || {
@@ -65,7 +64,7 @@ fn poll_it(state: &State) {
6564
// an `await` on something other than transaction requests. Abort in order to
6665
// avoid the default auto-commit behavior.
6766
let _ = state.transaction.abort();
68-
POLLED_FORBIDDEN_THING.store(true, Ordering::Relaxed);
67+
POLLED_FORBIDDEN_THING.set(true);
6968
panic!("Transaction blocked without any request under way");
7069
}
7170
}

0 commit comments

Comments
 (0)