fixed minor differences between 'compiled' generators and the example used. Added bonus section to prove it works

This commit is contained in:
Carl Fredrik Samson
2020-02-05 22:59:50 +01:00
parent 53529fa769
commit f9d3530949
9 changed files with 253 additions and 280 deletions

View File

@@ -188,7 +188,7 @@ fn main() {
reactor.lock().map(|mut r| r.close()).unwrap();
}
//// ===== EXECUTOR =====
// ============================= EXECUTOR ====================================
fn block_on<F: Future>(mut future: F) -> F::Output {
let mywaker = Arc::new(MyWaker{ thread: thread::current() });
let waker = waker_into_waker(Arc::into_raw(mywaker));
@@ -212,7 +212,7 @@ fn spawn<F: Future>(future: F) -> Pin<Box<F>> {
boxed
}
// ===== FUTURE IMPLEMENTATION =====
// ====================== FUTURE IMPLEMENTATION ==============================
#[derive(Clone)]
struct MyWaker {
thread: thread::Thread,
@@ -280,7 +280,7 @@ impl Future for Task {
}
}
// ===== REACTOR =====
// =============================== REACTOR ===================================
struct Reactor {
dispatcher: Sender<Event>,
handle: Option<JoinHandle<()>>,
@@ -301,7 +301,7 @@ impl Reactor {
let handle = thread::spawn(move || {
// This simulates some I/O resource
for event in rx {
println!("GOT EVENT: {:?}", event);
println!("REACTOR: {:?}", event);
let rl_clone = rl_clone.clone();
match event {
Event::Close => break,