Skip to content
6 changes: 3 additions & 3 deletions or_poisoned/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait OrPoisoned {
fn or_poisoned(self) -> Self::Inner;
}

impl<'a, T> OrPoisoned
impl<'a, T: ?Sized> OrPoisoned
for Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>>
{
type Inner = RwLockReadGuard<'a, T>;
Expand All @@ -45,7 +45,7 @@ impl<'a, T> OrPoisoned
}
}

impl<'a, T> OrPoisoned
impl<'a, T: ?Sized> OrPoisoned
for Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>>
{
type Inner = RwLockWriteGuard<'a, T>;
Expand All @@ -55,7 +55,7 @@ impl<'a, T> OrPoisoned
}
}

impl<'a, T> OrPoisoned for LockResult<MutexGuard<'a, T>> {
impl<'a, T: ?Sized> OrPoisoned for LockResult<MutexGuard<'a, T>> {
type Inner = MutexGuard<'a, T>;

fn or_poisoned(self) -> Self::Inner {
Expand Down
2 changes: 2 additions & 0 deletions reactive_graph/src/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#[allow(clippy::module_inception)]
mod effect;
mod effect_function;
mod immediate;
mod inner;
mod render_effect;

pub use effect::*;
pub use effect_function::*;
pub use immediate::*;
pub use render_effect::*;

/// Creates a new render effect, which immediately runs `fun`.
Expand Down
41 changes: 5 additions & 36 deletions reactive_graph/src/effect/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,47 +374,16 @@ impl Effect<SyncStorage> {
/// This spawns a task that can be run on any thread. For an effect that will be spawned on
/// the current thread, use [`new`](Effect::new).
pub fn new_sync<T, M>(
mut fun: impl EffectFunction<T, M> + Send + Sync + 'static,
fun: impl EffectFunction<T, M> + Send + Sync + 'static,
) -> Self
where
T: Send + Sync + 'static,
{
let inner = cfg!(feature = "effects").then(|| {
let (mut rx, owner, inner) = effect_base();
let mut first_run = true;
let value = Arc::new(RwLock::new(None::<T>));

crate::spawn({
let value = Arc::clone(&value);
let subscriber = inner.to_any_subscriber();

async move {
while rx.next().await.is_some() {
if !owner.paused()
&& (subscriber.with_observer(|| {
subscriber.update_if_necessary()
}) || first_run)
{
first_run = false;
subscriber.clear_sources(&subscriber);

let old_value =
mem::take(&mut *value.write().or_poisoned());
let new_value = owner.with_cleanup(|| {
subscriber.with_observer(|| {
run_in_effect_scope(|| fun.run(old_value))
})
});
*value.write().or_poisoned() = Some(new_value);
}
}
}
});

ArenaItem::new_with_storage(Some(inner))
});
if !cfg!(feature = "effects") {
return Self { inner: None };
}

Self { inner }
Self::new_isomorphic(fun)
}

/// Creates a new effect, which runs once on the next “tick”, and then runs again when reactive values
Expand Down
Loading
Loading