Remove push_future, get use_future kinda working again

This commit is contained in:
Jonathan Kelley committed 2024-01-15 19:34:04 -08:00
1 parent 14651a3573
commit a32ae8b112
8 files changed
+49 -60

No files matched your search

+2 -7
View File
@@ -62,14 +62,9 @@ pub fn suspend() -> Option<Element> {
None
}
/// Pushes the future onto the poll queue to be polled after the component renders.
pub fn push_future(fut: impl Future<Output = ()> + 'static) -> Option<Task> {
with_current_scope(|cx| cx.push_future(fut))
}
/// Spawns the future but does not return the [`TaskId`]
pub fn spawn(fut: impl Future<Output = ()> + 'static) {
with_current_scope(|cx| cx.spawn(fut));
pub fn spawn(fut: impl Future<Output = ()> + 'static) -> Task {
with_current_scope(|cx| cx.spawn(fut)).expect("to be in a dioxus runtime")
}
/// Spawn a future that Dioxus won't clean up when this component is unmounted
+3 -3
View File
@@ -87,9 +87,9 @@ pub mod prelude {
pub use crate::innerlude::{
consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, generation,
has_context, needs_update, parent_scope, provide_context, provide_root_context,
push_future, remove_future, schedule_update, schedule_update_any, spawn, spawn_forever,
suspend, try_consume_context, use_error_boundary, use_hook, AnyValue, Attribute, Component,
Element, ErrorBoundary, Event, EventHandler, Fragment, HasAttributes, IntoAttributeValue,
remove_future, schedule_update, schedule_update_any, spawn, spawn_forever, suspend,
try_consume_context, use_error_boundary, use_hook, AnyValue, Attribute, Component, Element,
ErrorBoundary, Event, EventHandler, Fragment, HasAttributes, IntoAttributeValue,
IntoDynNode, Properties, Runtime, RuntimeGuard, ScopeId, ScopeState, Task, Template,
TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner, VirtualDom,
};
+2 -2
View File
@@ -1,7 +1,7 @@
use futures_util::task::ArcWake;
use super::SchedulerMsg;
use crate::innerlude::{push_future, remove_future, Runtime};
use crate::innerlude::{remove_future, spawn, Runtime};
use crate::ScopeId;
use std::cell::RefCell;
use std::future::Future;
@@ -28,7 +28,7 @@ impl Task {
/// Spawning a future onto the root scope will cause it to be dropped when the root component is dropped - which
/// will only occur when the VirtualDom itself has been dropped.
pub fn new(task: impl Future<Output = ()> + 'static) -> Self {
push_future(task).expect("to be in a dioxus runtime")
spawn(task)
}
/// Drop the task immediately.
+3 -8
View File
@@ -225,18 +225,13 @@ impl ScopeContext {
.expect("Runtime to exist")
}
/// Pushes the future onto the poll queue to be polled after the component renders.
pub fn push_future(&self, fut: impl Future<Output = ()> + 'static) -> Task {
/// Spawns the future but does not return the [`TaskId`]
pub fn spawn(&self, fut: impl Future<Output = ()> + 'static) -> Task {
let id = with_runtime(|rt| rt.spawn(self.id, fut)).expect("Runtime to exist");
self.spawned_tasks.borrow_mut().insert(id);
id
}
/// Spawns the future but does not return the [`TaskId`]
pub fn spawn(&self, fut: impl Future<Output = ()> + 'static) {
self.push_future(fut);
}
/// Spawn a future that Dioxus won't clean up when this component is unmounted
///
/// This is good for tasks that need to be run after the component has been dropped.
@@ -369,7 +364,7 @@ impl ScopeId {
/// Pushes the future onto the poll queue to be polled after the component renders.
pub fn push_future(self, fut: impl Future<Output = ()> + 'static) -> Option<Task> {
with_scope(self, |cx| cx.push_future(fut))
with_scope(self, |cx| cx.spawn(fut))
}
/// Spawns the future but does not return the [`TaskId`]