suspense.rs 763 B

1234567891011121314151617181920212223242526272829303132
  1. use futures_util::task::ArcWake;
  2. use super::SchedulerMsg;
  3. use crate::ElementId;
  4. use crate::{innerlude::Mutations, Element, ScopeId};
  5. use std::future::Future;
  6. use std::sync::Arc;
  7. use std::task::Waker;
  8. use std::{
  9. cell::{Cell, RefCell},
  10. collections::HashSet,
  11. };
  12. /// A boundary in the VirtualDom that captures all suspended components below it
  13. pub struct SuspenseContext {
  14. pub(crate) id: ScopeId,
  15. pub(crate) waiting_on: RefCell<HashSet<ScopeId>>,
  16. }
  17. impl SuspenseContext {
  18. /// Create a new boundary for suspense
  19. pub fn new(id: ScopeId) -> Self {
  20. Self {
  21. id,
  22. waiting_on: Default::default(),
  23. }
  24. }
  25. pub fn mark_suspend(&self, id: ScopeId) {
  26. self.waiting_on.borrow_mut().insert(id);
  27. }
  28. }