Queue effects to run after flush_sync

This commit is contained in:
Jonathan Kelley committed 2024-01-28 02:21:05 -08:00
1 parent 7e4a1e9c7c
commit 1847c737e9
8 files changed
+137 -59

No files matched your search

+1 -3
View File
@@ -71,7 +71,7 @@ pub fn spawn_forever(fut: impl Future<Output = ()> + 'static) -> Option<Task> {
///
/// This drops the task immediately.
pub fn remove_future(id: Task) {
Runtime::with_current_scope(|cx| cx.remove_future(id));
Runtime::with(|rt| rt.remove_task(id)).expect("Runtime to exist");
}
/// Store a value between renders. The foundational hook for all other hooks.
@@ -94,7 +94,6 @@ pub fn use_hook<State: Clone + 'static>(initializer: impl FnOnce() -> State) ->
Runtime::with_current_scope(|cx| cx.use_hook(initializer)).expect("to be in a dioxus runtime")
}
/// Get the current render since the inception of this component
///
/// This can be used as a helpful diagnostic when debugging hooks/renders, etc
@@ -217,7 +216,6 @@ pub fn use_drop<D: FnOnce() + 'static>(destroy: D) {
});
}
/// Push a function to be run before the next render
/// This is a hook and will always run, so you can't unschedule it
/// Will run for every progression of suspense, though this might change in the future
-7
View File
@@ -234,13 +234,6 @@ impl Scope {
Runtime::with(|rt| rt.spawn(self.id, fut)).expect("Runtime to exist")
}
/// Informs the scheduler that this task is no longer needed and should be removed.
///
/// This drops the task immediately.
pub fn remove_future(&self, id: Task) {
Runtime::with(|rt| rt.remove_task(id)).expect("Runtime to exist");
}
/// Mark this component as suspended and then return None
pub fn suspend(&self) -> Option<Element> {
self.suspended.set(true);
+9 -2
View File
@@ -45,12 +45,19 @@ impl Task {
Runtime::with(|rt| !rt.tasks.borrow()[self.0].active.get()).unwrap_or_default()
}
pub fn wake(&self) {
Runtime::with(|rt| _ = rt.sender.unbounded_send(SchedulerMsg::TaskNotified(*self)));
}
pub fn set_active(&self, active: bool) {
Runtime::with(|rt| rt.tasks.borrow()[self.0].active.set(active));
}
/// Resume the task.
pub fn resume(&self) {
Runtime::with(|rt| {
// set the active flag, and then ping the scheduler to ensure the task gets queued
rt.tasks.borrow()[self.0].active.set(true);
_ = rt.sender.unbounded_send(SchedulerMsg::TaskNotified(*self));
let was_active = rt.tasks.borrow()[self.0].active.replace(true);
});
}
}