Last active
March 8, 2018 10:11
-
-
Save RCasatta/8ad62e8b8c67223d257a628b533baa9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate futures; | |
extern crate tokio; | |
use futures::{Future, Async, Poll}; | |
use std::thread; | |
use futures::sync::oneshot::Receiver; | |
use std::time; | |
use tokio::executor::current_thread; | |
pub struct FutureSender { | |
rx : Receiver<u32>, | |
} | |
impl FutureSender { | |
fn new(rx : Receiver<u32>) -> FutureSender { | |
FutureSender { | |
rx | |
} | |
} | |
} | |
impl Future for FutureSender { | |
type Item = (); | |
type Error = (); | |
fn poll(&mut self) -> Poll<Self::Item, Self::Error> { | |
match self.rx.poll().unwrap() { | |
Async::Ready(v) => { | |
println!("Async::Ready({:?})",v); | |
Ok(Async::Ready(())) | |
}, | |
Async::NotReady => { | |
println!("Async::NotReady"); | |
Ok(Async::NotReady) | |
}, | |
} | |
} | |
} | |
fn main() { | |
let (tx,rx) = futures::oneshot(); | |
let future_sender = FutureSender::new(rx); | |
let _ = thread::spawn(move || { | |
thread::sleep(time::Duration::from_secs(1)); | |
println!("set"); | |
tx.send(10); | |
}); | |
current_thread::run(|_| { | |
current_thread::spawn(future_sender); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment