|
@@ -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();
|