mod.rs 873 B

12345678910111213141516171819202122232425262728293031323334353637
  1. use crate::ScopeId;
  2. use slab::Slab;
  3. mod task;
  4. mod wait;
  5. pub use task::*;
  6. /// The type of message that can be sent to the scheduler.
  7. ///
  8. /// These messages control how the scheduler will process updates to the UI.
  9. #[derive(Debug)]
  10. pub(crate) enum SchedulerMsg {
  11. /// Immediate updates from Components that mark them as dirty
  12. Immediate(ScopeId),
  13. /// A task has woken and needs to be progressed
  14. TaskNotified(TaskId),
  15. }
  16. use std::{cell::RefCell, rc::Rc};
  17. pub(crate) struct Scheduler {
  18. pub sender: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
  19. /// Tasks created with cx.spawn
  20. pub tasks: RefCell<Slab<LocalTask>>,
  21. }
  22. impl Scheduler {
  23. pub fn new(sender: futures_channel::mpsc::UnboundedSender<SchedulerMsg>) -> Rc<Self> {
  24. Rc::new(Scheduler {
  25. sender,
  26. tasks: RefCell::new(Slab::new()),
  27. })
  28. }
  29. }