Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::thread::{sleep, spawn};
- use std::time::Duration;
- extern crate futures; // 0.2.1
- use futures::channel::mpsc;
- use futures::executor::LocalPool;
- use futures::task::Context;
- use futures::{Async, Future, Never};
- use futures::future::loop_fn;
- use futures::StreamExt;
- use futures::FutureExt;
- use futures::future::Loop;
- // ожидание прерывания от ядра
- fn epoll_wait() -> std::io::Result<()> {
- sleep(Duration::from_millis(100));
- Ok(())
- }
- fn main() {
- let (mut irq_tx, irq_rx) = mpsc::channel(1);
- let mut pool = LocalPool::new();
- let mut executor = pool.executor();
- //let notify = Notify { irq: irq_rx };
- spawn(move || {
- while let Ok(_) = epoll_wait() {
- // Возможно ли здесь разместить Waker от Notify?
- // что бы будить ее
- if let Err(err) = irq_tx.try_send(()) {
- println!("Send irq to notify error: {}", err);
- } else {
- println!("Send irq to notify successfully");
- }
- }
- });
- executor.spawn_local(
- loop_fn(irq_rx.next(), |future|
- future
- .map(|(item, stream)|{
- println!("Irq receive: {:?}", item);
- Loop::Continue(stream.next())
- })
- .map_err(|(err, _)| err)
- )
- ).unwrap();
- pool.run(&mut executor);
- }
Add Comment
Please, Sign In to add comment