Skip to content

Commit

Permalink
crash any other threads with an error message
Browse files Browse the repository at this point in the history
crash any other threads with an error message if signals are acessed from that thread. 

It would be better to have a solution that makes it so that at compile time users would get an error if signals are used improperly, but at least now there will be an error message
  • Loading branch information
jrmoulton committed Oct 20, 2024
1 parent 005076b commit e8998eb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion reactive/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
cell::{Cell, RefCell},
collections::{HashMap, HashSet},
rc::Rc,
sync::atomic::{AtomicBool, Ordering},
};

use smallvec::SmallVec;
Expand All @@ -13,8 +14,14 @@ use crate::{
signal::Signal,
};

static CREATED: AtomicBool = AtomicBool::new(false);
thread_local! {
pub(crate) static RUNTIME: Runtime = Runtime::new();
pub(crate) static RUNTIME: Runtime = {
if CREATED.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst).is_err() {
panic!("RUNTIME must only be created once. You are probably using signals from multiple threads. All signals need to be accessed exclusively from the main thread.");
}
Runtime::new()
};
}

/// The internal reactive Runtime which stores all the reactive system states in a
Expand Down

0 comments on commit e8998eb

Please sign in to comment.