浏览代码

chore: use std::future::Future instead

Jonathan Kelley 2 年之前
父节点
当前提交
f7df6a9893

+ 1 - 1
packages/core/src/any_props.rs

@@ -1,6 +1,6 @@
 use std::marker::PhantomData;
 use std::marker::PhantomData;
 
 
-use futures_util::Future;
+use std::future::Future;
 
 
 use crate::{
 use crate::{
     factory::{ComponentReturn, RenderReturn},
     factory::{ComponentReturn, RenderReturn},

+ 1 - 1
packages/core/src/component.rs

@@ -4,7 +4,7 @@
 
 
 use std::marker::PhantomData;
 use std::marker::PhantomData;
 
 
-use futures_util::Future;
+use std::future::Future;
 
 
 use crate::{scopes::Scope, Element};
 use crate::{scopes::Scope, Element};
 
 

+ 1 - 1
packages/core/src/factory.rs

@@ -2,7 +2,7 @@ use std::{cell::Cell, fmt::Arguments, pin::Pin};
 
 
 use bumpalo::boxed::Box as BumpBox;
 use bumpalo::boxed::Box as BumpBox;
 use bumpalo::Bump;
 use bumpalo::Bump;
-use futures_util::Future;
+use std::future::Future;
 
 
 use crate::{
 use crate::{
     any_props::{AnyProps, VComponentProps},
     any_props::{AnyProps, VComponentProps},

+ 1 - 1
packages/core/src/future_container.rs

@@ -1,6 +1,6 @@
 use futures_channel::mpsc::UnboundedSender;
 use futures_channel::mpsc::UnboundedSender;
-use futures_util::Future;
 use slab::Slab;
 use slab::Slab;
+use std::future::Future;
 use std::{cell::RefCell, rc::Rc, sync::Arc};
 use std::{cell::RefCell, rc::Rc, sync::Arc};
 
 
 use crate::innerlude::ScopeId;
 use crate::innerlude::ScopeId;

+ 1 - 1
packages/core/src/scheduler.old.rs

@@ -1,8 +1,8 @@
 use std::{cell::RefCell, rc::Rc, sync::Arc};
 use std::{cell::RefCell, rc::Rc, sync::Arc};
 
 
 use futures_task::ArcWake;
 use futures_task::ArcWake;
-use futures_util::Future;
 use slab::Slab;
 use slab::Slab;
+use std::future::Future;
 
 
 use crate::{innerlude::Mutation, ScopeId};
 use crate::{innerlude::Mutation, ScopeId};
 
 

+ 4 - 14
packages/core/src/scheduler/mod.rs

@@ -33,17 +33,7 @@ pub enum SchedulerMsg {
 
 
 use std::{cell::RefCell, rc::Rc};
 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>,
     pub sender: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
 
 
     /// Tasks created with cx.spawn
     /// Tasks created with cx.spawn
@@ -54,11 +44,11 @@ pub struct HandleInner {
 }
 }
 
 
 impl Scheduler {
 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,
             sender,
             tasks: RefCell::new(Slab::new()),
             tasks: RefCell::new(Slab::new()),
             leaves: RefCell::new(Slab::new()),
             leaves: RefCell::new(Slab::new()),
-        }))
+        })
     }
     }
 }
 }

+ 3 - 8
packages/core/src/scheduler/suspense.rs

@@ -1,17 +1,12 @@
+use super::{waker::RcWake, SchedulerMsg};
+use crate::{innerlude::Mutations, Element, ScopeId};
+use std::future::Future;
 use std::{
 use std::{
     cell::{Cell, RefCell},
     cell::{Cell, RefCell},
     collections::HashSet,
     collections::HashSet,
     rc::Rc,
     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)]
 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
 pub struct SuspenseId(pub usize);
 pub struct SuspenseId(pub usize);
 
 

+ 8 - 23
packages/core/src/scheduler/task.rs

@@ -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))]
 #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
 pub struct TaskId(pub usize);
 pub struct TaskId(pub usize);
 
 
 /// the task itself is the waker
 /// the task itself is the waker
-
-pub struct LocalTask {
+pub(crate) struct LocalTask {
     pub id: TaskId,
     pub id: TaskId,
     pub scope: ScopeId,
     pub scope: ScopeId,
     pub tx: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
     pub tx: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
@@ -41,14 +26,14 @@ impl LocalTask {
         // safety: the waker owns its task and everythig is single threaded
         // safety: the waker owns its task and everythig is single threaded
         let fut = unsafe { &mut *self.task.get() };
         let fut = unsafe { &mut *self.task.get() };
 
 
-        match fut.poll_unpin(&mut cx) {
+        match Pin::new(fut).poll(&mut cx) {
             Poll::Ready(_) => true,
             Poll::Ready(_) => true,
             _ => false,
             _ => false,
         }
         }
     }
     }
 }
 }
 
 
-impl HandleInner {
+impl Scheduler {
     pub fn spawn(&self, scope: ScopeId, task: impl Future<Output = ()> + 'static) -> TaskId {
     pub fn spawn(&self, scope: ScopeId, task: impl Future<Output = ()> + 'static) -> TaskId {
         let mut tasks = self.tasks.borrow_mut();
         let mut tasks = self.tasks.borrow_mut();
         let entry = tasks.vacant_entry();
         let entry = tasks.vacant_entry();

+ 3 - 2
packages/core/src/scopes.rs

@@ -2,12 +2,13 @@ use std::{
     any::{Any, TypeId},
     any::{Any, TypeId},
     cell::{Cell, RefCell},
     cell::{Cell, RefCell},
     collections::{HashMap, HashSet},
     collections::{HashMap, HashSet},
+    rc::Rc,
     sync::Arc,
     sync::Arc,
 };
 };
 
 
 use bumpalo::Bump;
 use bumpalo::Bump;
 use futures_channel::mpsc::UnboundedSender;
 use futures_channel::mpsc::UnboundedSender;
-use futures_util::Future;
+use std::future::Future;
 
 
 use crate::{
 use crate::{
     any_props::AnyProps,
     any_props::AnyProps,
@@ -60,7 +61,7 @@ pub struct ScopeState {
 
 
     pub(crate) shared_contexts: RefCell<HashMap<TypeId, Box<dyn Any>>>,
     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) spawned_tasks: HashSet<TaskId>,
 
 
     pub(crate) props: *mut dyn AnyProps<'static>,
     pub(crate) props: *mut dyn AnyProps<'static>,

+ 3 - 2
packages/core/src/virtual_dom.rs

@@ -11,10 +11,11 @@ use crate::{
 };
 };
 use crate::{scheduler, Element, Scope};
 use crate::{scheduler, Element, Scope};
 use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
 use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
-use futures_util::Future;
 use scheduler::{SuspenseBoundary, SuspenseId};
 use scheduler::{SuspenseBoundary, SuspenseId};
 use slab::Slab;
 use slab::Slab;
 use std::collections::{BTreeSet, HashMap};
 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.
 /// 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) scopes: Slab<ScopeState>,
     pub(crate) element_stack: Vec<ElementId>,
     pub(crate) element_stack: Vec<ElementId>,
     pub(crate) dirty_scopes: BTreeSet<DirtyScope>,
     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.
     // While diffing we need some sort of way of breaking off a stream of suspended mutations.
     pub(crate) scope_stack: Vec<ScopeId>,
     pub(crate) scope_stack: Vec<ScopeId>,