Guest User

Untitled

a guest
Jun 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. use std::thread::{sleep, spawn};
  2. use std::time::Duration;
  3.  
  4. extern crate futures; // 0.2.1
  5. use futures::channel::mpsc;
  6. use futures::executor::LocalPool;
  7. use futures::task::Context;
  8. use futures::{Async, Future, Never};
  9. use futures::future::loop_fn;
  10. use futures::StreamExt;
  11. use futures::FutureExt;
  12. use futures::future::Loop;
  13.  
  14.  
  15. // ожидание прерывания от ядра
  16. fn epoll_wait() -> std::io::Result<()> {
  17. sleep(Duration::from_millis(100));
  18. Ok(())
  19. }
  20.  
  21. fn main() {
  22. let (mut irq_tx, irq_rx) = mpsc::channel(1);
  23.  
  24. let mut pool = LocalPool::new();
  25. let mut executor = pool.executor();
  26. //let notify = Notify { irq: irq_rx };
  27.  
  28. spawn(move || {
  29. while let Ok(_) = epoll_wait() {
  30. // Возможно ли здесь разместить Waker от Notify?
  31. // что бы будить ее
  32. if let Err(err) = irq_tx.try_send(()) {
  33. println!("Send irq to notify error: {}", err);
  34. } else {
  35. println!("Send irq to notify successfully");
  36. }
  37. }
  38. });
  39.  
  40. executor.spawn_local(
  41. loop_fn(irq_rx.next(), |future|
  42. future
  43. .map(|(item, stream)|{
  44. println!("Irq receive: {:?}", item);
  45. Loop::Continue(stream.next())
  46. })
  47. .map_err(|(err, _)| err)
  48. )
  49. ).unwrap();
  50.  
  51. pool.run(&mut executor);
  52. }
Add Comment
Please, Sign In to add comment