mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-17 06:08:26 +00:00
chore: use std::future::Future instead
This commit is contained in:
parent
f5bc137f01
commit
f7df6a9893
10 changed files with 26 additions and 54 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use futures_util::Future;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::{
|
||||
factory::{ComponentReturn, RenderReturn},
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use futures_util::Future;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::{scopes::Scope, Element};
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{cell::Cell, fmt::Arguments, pin::Pin};
|
|||
|
||||
use bumpalo::boxed::Box as BumpBox;
|
||||
use bumpalo::Bump;
|
||||
use futures_util::Future;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::{
|
||||
any_props::{AnyProps, VComponentProps},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use futures_channel::mpsc::UnboundedSender;
|
||||
use futures_util::Future;
|
||||
use slab::Slab;
|
||||
use std::future::Future;
|
||||
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||
|
||||
use crate::innerlude::ScopeId;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||
|
||||
use futures_task::ArcWake;
|
||||
use futures_util::Future;
|
||||
use slab::Slab;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::{innerlude::Mutation, ScopeId};
|
||||
|
||||
|
|
|
@ -33,17 +33,7 @@ pub enum SchedulerMsg {
|
|||
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct Scheduler(Rc<HandleInner>);
|
||||
|
||||
impl std::ops::Deref for Scheduler {
|
||||
type Target = HandleInner;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HandleInner {
|
||||
pub(crate) struct Scheduler {
|
||||
pub sender: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
|
||||
|
||||
/// Tasks created with cx.spawn
|
||||
|
@ -54,11 +44,11 @@ pub struct HandleInner {
|
|||
}
|
||||
|
||||
impl Scheduler {
|
||||
pub fn new(sender: futures_channel::mpsc::UnboundedSender<SchedulerMsg>) -> Self {
|
||||
Self(Rc::new(HandleInner {
|
||||
pub fn new(sender: futures_channel::mpsc::UnboundedSender<SchedulerMsg>) -> Rc<Self> {
|
||||
Rc::new(Scheduler {
|
||||
sender,
|
||||
tasks: RefCell::new(Slab::new()),
|
||||
leaves: RefCell::new(Slab::new()),
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
use super::{waker::RcWake, SchedulerMsg};
|
||||
use crate::{innerlude::Mutations, Element, ScopeId};
|
||||
use std::future::Future;
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
collections::HashSet,
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
use super::{waker::RcWake, SchedulerMsg};
|
||||
use crate::{
|
||||
innerlude::{Mutation, Mutations},
|
||||
Element, ScopeId,
|
||||
};
|
||||
|
||||
use futures_util::Future;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct SuspenseId(pub usize);
|
||||
|
||||
|
|
|
@ -1,30 +1,15 @@
|
|||
use std::{
|
||||
cell::{RefCell, UnsafeCell},
|
||||
marker::PhantomData,
|
||||
mem::{self, MaybeUninit},
|
||||
ops::DerefMut,
|
||||
pin::Pin,
|
||||
process::Output,
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
task::Poll,
|
||||
};
|
||||
|
||||
use futures_util::{pin_mut, Future, FutureExt};
|
||||
use slab::Slab;
|
||||
use std::task::{Context, RawWaker, RawWakerVTable, Waker};
|
||||
|
||||
use crate::{Element, ScopeId};
|
||||
|
||||
use super::{waker::RcWake, HandleInner, Scheduler, SchedulerMsg};
|
||||
use super::{waker::RcWake, Scheduler, SchedulerMsg};
|
||||
use crate::ScopeId;
|
||||
use std::future::Future;
|
||||
use std::task::Context;
|
||||
use std::{cell::UnsafeCell, pin::Pin, rc::Rc, task::Poll};
|
||||
|
||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct TaskId(pub usize);
|
||||
|
||||
/// the task itself is the waker
|
||||
|
||||
pub struct LocalTask {
|
||||
pub(crate) struct LocalTask {
|
||||
pub id: TaskId,
|
||||
pub scope: ScopeId,
|
||||
pub tx: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
|
||||
|
@ -41,14 +26,14 @@ impl LocalTask {
|
|||
// safety: the waker owns its task and everythig is single threaded
|
||||
let fut = unsafe { &mut *self.task.get() };
|
||||
|
||||
match fut.poll_unpin(&mut cx) {
|
||||
match Pin::new(fut).poll(&mut cx) {
|
||||
Poll::Ready(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HandleInner {
|
||||
impl Scheduler {
|
||||
pub fn spawn(&self, scope: ScopeId, task: impl Future<Output = ()> + 'static) -> TaskId {
|
||||
let mut tasks = self.tasks.borrow_mut();
|
||||
let entry = tasks.vacant_entry();
|
||||
|
|
|
@ -2,12 +2,13 @@ use std::{
|
|||
any::{Any, TypeId},
|
||||
cell::{Cell, RefCell},
|
||||
collections::{HashMap, HashSet},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use bumpalo::Bump;
|
||||
use futures_channel::mpsc::UnboundedSender;
|
||||
use futures_util::Future;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::{
|
||||
any_props::AnyProps,
|
||||
|
@ -60,7 +61,7 @@ pub struct ScopeState {
|
|||
|
||||
pub(crate) shared_contexts: RefCell<HashMap<TypeId, Box<dyn Any>>>,
|
||||
|
||||
pub(crate) tasks: Scheduler,
|
||||
pub(crate) tasks: Rc<Scheduler>,
|
||||
pub(crate) spawned_tasks: HashSet<TaskId>,
|
||||
|
||||
pub(crate) props: *mut dyn AnyProps<'static>,
|
||||
|
|
|
@ -11,10 +11,11 @@ use crate::{
|
|||
};
|
||||
use crate::{scheduler, Element, Scope};
|
||||
use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||
use futures_util::Future;
|
||||
use scheduler::{SuspenseBoundary, SuspenseId};
|
||||
use slab::Slab;
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::future::Future;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// A virtual node system that progresses user events and diffs UI trees.
|
||||
///
|
||||
|
@ -113,7 +114,7 @@ pub struct VirtualDom {
|
|||
pub(crate) scopes: Slab<ScopeState>,
|
||||
pub(crate) element_stack: Vec<ElementId>,
|
||||
pub(crate) dirty_scopes: BTreeSet<DirtyScope>,
|
||||
pub(crate) scheduler: Scheduler,
|
||||
pub(crate) scheduler: Rc<Scheduler>,
|
||||
|
||||
// While diffing we need some sort of way of breaking off a stream of suspended mutations.
|
||||
pub(crate) scope_stack: Vec<ScopeId>,
|
||||
|
|
Loading…
Add table
Reference in a new issue