Fix effect ordering after reruns
This commit is contained in:
1 parent
26f5fb80cb
commit
a14e5be7ad
8 files changed
+89
-51
No files matched your search
@@ -3,11 +3,11 @@ use crate::{
|
||||
scope_context::Scope,
|
||||
scopes::ScopeId,
|
||||
Task,
|
||||
render_signal::RenderSignal
|
||||
};
|
||||
use std::{
|
||||
cell::{Cell, Ref, RefCell},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
thread_local! {
|
||||
@@ -31,18 +31,15 @@ pub struct Runtime {
|
||||
|
||||
pub(crate) sender: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
|
||||
|
||||
// the virtualdom will hold this lock while it's doing syncronous work
|
||||
// when the lock is lifted, tasks waiting for the lock will be able to run
|
||||
pub(crate) flush_mutex: Arc<futures_util::lock::Mutex<()>>,
|
||||
pub(crate) flush_lock: Cell<Option<futures_util::lock::OwnedMutexGuard<()>>>,
|
||||
// Synchronous tasks need to be run after the next render. The virtual dom stores a list of those tasks to send a signal to them when the next render is done.
|
||||
pub(crate) render_signal: RenderSignal,
|
||||
}
|
||||
|
||||
impl Runtime {
|
||||
pub(crate) fn new(sender: futures_channel::mpsc::UnboundedSender<SchedulerMsg>) -> Rc<Self> {
|
||||
Rc::new(Self {
|
||||
sender,
|
||||
flush_mutex: Default::default(),
|
||||
flush_lock: Default::default(),
|
||||
render_signal: RenderSignal::default(),
|
||||
rendering: Cell::new(true),
|
||||
scope_states: Default::default(),
|
||||
scope_stack: Default::default(),
|
||||
@@ -149,25 +146,6 @@ impl Runtime {
|
||||
pub(crate) fn with_scope<R>(scope: ScopeId, f: impl FnOnce(&Scope) -> R) -> Option<R> {
|
||||
Self::with(|rt| rt.get_state(scope).map(|sc| f(&sc))).flatten()
|
||||
}
|
||||
|
||||
/// Acquire the flush lock and store it interally
|
||||
///
|
||||
/// This means the virtual dom is currently doing syncronous work
|
||||
/// The lock will be held until `release_flush_lock` is called - and then the OwnedLock will be dropped
|
||||
pub(crate) fn acquire_flush_lock(&self) {
|
||||
// The flush lock might already be held...
|
||||
if let Some(lock) = self.flush_mutex.try_lock_owned() {
|
||||
self.flush_lock.set(Some(lock));
|
||||
}
|
||||
}
|
||||
|
||||
/// Release the flush lock
|
||||
///
|
||||
/// On the drop of the flush lock, all tasks waiting on `flush_sync` will spring to life via their wakers.
|
||||
/// You can now freely poll those tasks and they can progress
|
||||
pub(crate) fn release_flush_lock(&self) {
|
||||
self.flush_lock.take();
|
||||
}
|
||||
}
|
||||
|
||||
/// A guard for a new runtime. This must be used to override the current runtime when importing components from a dynamic library that has it's own runtime.
|
||||
|
||||
Reference in new issue
Block a user