1
0

tasks.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. use crate::innerlude::*;
  2. use futures_channel::mpsc::UnboundedSender;
  3. pub struct TaskHandle {
  4. pub(crate) sender: UnboundedSender<SchedulerMsg>,
  5. pub(crate) our_id: u64,
  6. }
  7. impl TaskHandle {
  8. /// Toggles this coroutine off/on.
  9. ///
  10. /// This method is not synchronous - your task will not stop immediately.
  11. pub fn toggle(&self) {
  12. self.sender
  13. .unbounded_send(SchedulerMsg::Task(TaskMsg::ToggleTask(self.our_id)))
  14. .unwrap()
  15. }
  16. /// This method is not synchronous - your task will not stop immediately.
  17. pub fn resume(&self) {
  18. self.sender
  19. .unbounded_send(SchedulerMsg::Task(TaskMsg::ResumeTask(self.our_id)))
  20. .unwrap()
  21. }
  22. /// This method is not synchronous - your task will not stop immediately.
  23. pub fn stop(&self) {
  24. self.sender
  25. .unbounded_send(SchedulerMsg::Task(TaskMsg::ToggleTask(self.our_id)))
  26. .unwrap()
  27. }
  28. /// This method is not synchronous - your task will not stop immediately.
  29. pub fn restart(&self) {
  30. self.sender
  31. .unbounded_send(SchedulerMsg::Task(TaskMsg::ToggleTask(self.our_id)))
  32. .unwrap()
  33. }
  34. }