Exercises

  1. Write function waker_fn which “converts a closure into a Waker”.
  2. Write function waker_unpark which creates a waker. The waker unparks a given thread when waking.
  3. Write function block_on which “blocks the current thread on a future”.
  4. Rewrite Recv to support the Waker pattern. Name the new struct RecvWithWaker.
  5. Rewrite “reactor-hello” using RecvWithWaker and block_on.

Solutions

  1. See examples/src/waker_fn.rs
  2. See examples/src/block_on.rs
  3. See examples/src/block_on.rs
  4. See examples/src/recv_with_waker.rs
  5. See examples/src/bin/block-on-hello.rs