Skip to content

Commit a4e47d4

Browse files
authored
Merge pull request #3650 from QuartzLibrary/immediate-effect
`ImmediateEffect`
2 parents 3164721 + 38a3aae commit a4e47d4

File tree

6 files changed

+596
-48
lines changed

6 files changed

+596
-48
lines changed

or_poisoned/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait OrPoisoned {
3535
fn or_poisoned(self) -> Self::Inner;
3636
}
3737

38-
impl<'a, T> OrPoisoned
38+
impl<'a, T: ?Sized> OrPoisoned
3939
for Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>>
4040
{
4141
type Inner = RwLockReadGuard<'a, T>;
@@ -45,7 +45,7 @@ impl<'a, T> OrPoisoned
4545
}
4646
}
4747

48-
impl<'a, T> OrPoisoned
48+
impl<'a, T: ?Sized> OrPoisoned
4949
for Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>>
5050
{
5151
type Inner = RwLockWriteGuard<'a, T>;
@@ -55,7 +55,7 @@ impl<'a, T> OrPoisoned
5555
}
5656
}
5757

58-
impl<'a, T> OrPoisoned for LockResult<MutexGuard<'a, T>> {
58+
impl<'a, T: ?Sized> OrPoisoned for LockResult<MutexGuard<'a, T>> {
5959
type Inner = MutexGuard<'a, T>;
6060

6161
fn or_poisoned(self) -> Self::Inner {

reactive_graph/src/effect.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#[allow(clippy::module_inception)]
44
mod effect;
55
mod effect_function;
6+
mod immediate;
67
mod inner;
78
mod render_effect;
89

910
pub use effect::*;
1011
pub use effect_function::*;
12+
pub use immediate::*;
1113
pub use render_effect::*;
1214

1315
/// Creates a new render effect, which immediately runs `fun`.

reactive_graph/src/effect/effect.rs

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -374,47 +374,16 @@ impl Effect<SyncStorage> {
374374
/// This spawns a task that can be run on any thread. For an effect that will be spawned on
375375
/// the current thread, use [`new`](Effect::new).
376376
pub fn new_sync<T, M>(
377-
mut fun: impl EffectFunction<T, M> + Send + Sync + 'static,
377+
fun: impl EffectFunction<T, M> + Send + Sync + 'static,
378378
) -> Self
379379
where
380380
T: Send + Sync + 'static,
381381
{
382-
let inner = cfg!(feature = "effects").then(|| {
383-
let (mut rx, owner, inner) = effect_base();
384-
let mut first_run = true;
385-
let value = Arc::new(RwLock::new(None::<T>));
386-
387-
crate::spawn({
388-
let value = Arc::clone(&value);
389-
let subscriber = inner.to_any_subscriber();
390-
391-
async move {
392-
while rx.next().await.is_some() {
393-
if !owner.paused()
394-
&& (subscriber.with_observer(|| {
395-
subscriber.update_if_necessary()
396-
}) || first_run)
397-
{
398-
first_run = false;
399-
subscriber.clear_sources(&subscriber);
400-
401-
let old_value =
402-
mem::take(&mut *value.write().or_poisoned());
403-
let new_value = owner.with_cleanup(|| {
404-
subscriber.with_observer(|| {
405-
run_in_effect_scope(|| fun.run(old_value))
406-
})
407-
});
408-
*value.write().or_poisoned() = Some(new_value);
409-
}
410-
}
411-
}
412-
});
413-
414-
ArenaItem::new_with_storage(Some(inner))
415-
});
382+
if !cfg!(feature = "effects") {
383+
return Self { inner: None };
384+
}
416385

417-
Self { inner }
386+
Self::new_isomorphic(fun)
418387
}
419388

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

0 commit comments

Comments
 (0)