use std::{cell::RefCell, rc::Rc, sync::Arc}; use futures_task::ArcWake; use slab::Slab; use std::future::Future; use crate::{innerlude::Mutation, ScopeId}; type Shared = Rc>; struct LocalTask {} pub struct Fiber { // The work-in progress of this suspended tree pub mutations: Vec>, } #[derive(Clone)] pub struct SchedulerHandle { tasks: Shared>, suspended: Shared>, fibers: Shared>, tx: futures_channel::mpsc::UnboundedSender, } struct TaskEntry {} struct LocalTaskWaker { future: T, id: TaskId, tx: futures_channel::mpsc::UnboundedSender, } unsafe impl Send for LocalTaskWaker {} unsafe impl Sync for LocalTaskWaker {} impl ArcWake for LocalTaskWaker { fn wake(self: Arc) { Self::wake_by_ref(&self) } fn wake_by_ref(arc_self: &Arc) { arc_self .tx .unbounded_send(SchedulerMsg::TaskNotified(arc_self.id)) .unwrap(); } } impl SchedulerHandle { fn spawn(&self, fut: impl Future + 'static) -> TaskId { use futures_task::waker; let tasks = self.tasks.borrow_mut(); let entry = tasks.vacant_entry(); let id = TaskId(entry.key()); let task = Arc::new(LocalTaskWaker { future: fut, id, tx: self.tx.clone(), }); let local_task = waker(task.clone()); entry.insert(val); // todo!() } fn remove(&self, id: TaskId) { // } }