fix outdated links re: #13
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en" class="sidebar-visible no-js light">
|
||||
<html lang="en" class="sidebar-visible no-js">
|
||||
<head>
|
||||
<!-- Book generated using mdBook -->
|
||||
<meta charset="UTF-8">
|
||||
@@ -32,11 +32,11 @@
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<body class="light">
|
||||
<!-- Provide site root to javascript -->
|
||||
<script type="text/javascript">
|
||||
var path_to_root = "";
|
||||
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "light" : "light";
|
||||
var default_theme = "light";
|
||||
</script>
|
||||
|
||||
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
||||
@@ -60,11 +60,8 @@
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
||||
if (theme === null || theme === undefined) { theme = default_theme; }
|
||||
var html = document.querySelector('html');
|
||||
html.classList.remove('no-js')
|
||||
html.classList.remove('light')
|
||||
html.classList.add(theme);
|
||||
html.classList.add('js');
|
||||
document.body.className = theme;
|
||||
document.querySelector('html').className = theme + ' js';
|
||||
</script>
|
||||
|
||||
<!-- Hide / unhide sidebar before it is displayed -->
|
||||
@@ -80,8 +77,8 @@
|
||||
</script>
|
||||
|
||||
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
|
||||
<div id="sidebar-scrollbox" class="sidebar-scrollbox">
|
||||
<ol class="chapter"><li class="expanded affix "><a href="introduction.html">Introduction</a></li><li class="expanded "><a href="0_background_information.html"><strong aria-hidden="true">1.</strong> Background information</a></li><li class="expanded "><a href="1_futures_in_rust.html"><strong aria-hidden="true">2.</strong> Futures in Rust</a></li><li class="expanded "><a href="2_waker_context.html"><strong aria-hidden="true">3.</strong> Waker and Context</a></li><li class="expanded "><a href="3_generators_async_await.html"><strong aria-hidden="true">4.</strong> Generators and async/await</a></li><li class="expanded "><a href="4_pin.html"><strong aria-hidden="true">5.</strong> Pin</a></li><li class="expanded "><a href="6_future_example.html" class="active"><strong aria-hidden="true">6.</strong> Implementing Futures</a></li><li class="expanded "><a href="8_finished_example.html"><strong aria-hidden="true">7.</strong> Finished example (editable)</a></li><li class="expanded affix "><a href="conclusion.html">Conclusion and exercises</a></li></ol>
|
||||
<div class="sidebar-scrollbox">
|
||||
<ol class="chapter"><li class="affix"><a href="introduction.html">Introduction</a></li><li><a href="0_background_information.html"><strong aria-hidden="true">1.</strong> Background information</a></li><li><a href="1_futures_in_rust.html"><strong aria-hidden="true">2.</strong> Futures in Rust</a></li><li><a href="2_waker_context.html"><strong aria-hidden="true">3.</strong> Waker and Context</a></li><li><a href="3_generators_async_await.html"><strong aria-hidden="true">4.</strong> Generators and async/await</a></li><li><a href="4_pin.html"><strong aria-hidden="true">5.</strong> Pin</a></li><li><a href="6_future_example.html" class="active"><strong aria-hidden="true">6.</strong> Implementing Futures</a></li><li><a href="8_finished_example.html"><strong aria-hidden="true">7.</strong> Finished example (editable)</a></li><li class="affix"><a href="conclusion.html">Conclusion and exercises</a></li></ol>
|
||||
</div>
|
||||
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
|
||||
</nav>
|
||||
@@ -382,7 +379,7 @@ trouble of creating our own <code>vtable</code> and a <code>RawWaker</code>. We
|
||||
a normal trait.</p>
|
||||
<p>Fortunately, in the future this will probably be possible in the standard
|
||||
library as well. For now, <a href="https://rust-lang-nursery.github.io/futures-api-docs/0.3.0-alpha.13/futures/task/trait.ArcWake.html">this trait lives in the nursery</a>, but my
|
||||
guess is that this will be a part of the standard library after som maturing.</p>
|
||||
guess is that this will be a part of the standard library after some maturing.</p>
|
||||
<p>We choose to pass in a reference to the whole <code>Reactor</code> here. This isn't normal.
|
||||
The reactor will often be a global resource which let's us register interests
|
||||
without passing around a reference.</p>
|
||||
@@ -561,13 +558,13 @@ and make it sleep for some time which we specify when we create a <code>Task</co
|
||||
of seconds here, just give it some time to run.</p>
|
||||
<p>In the last chapter we have the <a href="./8_finished_example.html">whole 200 lines in an editable window</a>
|
||||
which you can edit and change the way you like.</p>
|
||||
<pre><pre class="playpen"><code class="language-rust edition2018"><span class="boring">use std::{
|
||||
</span><span class="boring"> future::Future, pin::Pin, sync::{ mpsc::{channel, Sender}, Arc, Mutex,},
|
||||
</span><span class="boring"> task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, mem,
|
||||
</span><span class="boring"> thread::{self, JoinHandle}, time::{Duration, Instant}, collections::HashMap
|
||||
</span><span class="boring">};
|
||||
</span><span class="boring">
|
||||
</span>fn main() {
|
||||
<pre><pre class="playpen"><code class="language-rust edition2018"># use std::{
|
||||
# future::Future, pin::Pin, sync::{ mpsc::{channel, Sender}, Arc, Mutex,},
|
||||
# task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, mem,
|
||||
# thread::{self, JoinHandle}, time::{Duration, Instant}, collections::HashMap
|
||||
# };
|
||||
#
|
||||
fn main() {
|
||||
// This is just to make it easier for us to see when our Future was resolved
|
||||
let start = Instant::now();
|
||||
|
||||
@@ -608,177 +605,177 @@ which you can edit and change the way you like.</p>
|
||||
// ends nicely.
|
||||
reactor.lock().map(|mut r| r.close()).unwrap();
|
||||
}
|
||||
<span class="boring">// ============================= EXECUTOR ====================================
|
||||
</span><span class="boring">fn block_on<F: Future>(mut future: F) -> F::Output {
|
||||
</span><span class="boring"> let mywaker = Arc::new(MyWaker {
|
||||
</span><span class="boring"> thread: thread::current(),
|
||||
</span><span class="boring"> });
|
||||
</span><span class="boring"> let waker = waker_into_waker(Arc::into_raw(mywaker));
|
||||
</span><span class="boring"> let mut cx = Context::from_waker(&waker);
|
||||
</span><span class="boring">
|
||||
</span><span class="boring"> // SAFETY: we shadow `future` so it can't be accessed again.
|
||||
</span><span class="boring"> let mut future = unsafe { Pin::new_unchecked(&mut future) };
|
||||
</span><span class="boring"> let val = loop {
|
||||
</span><span class="boring"> match Future::poll(future.as_mut(), &mut cx) {
|
||||
</span><span class="boring"> Poll::Ready(val) => break val,
|
||||
</span><span class="boring"> Poll::Pending => thread::park(),
|
||||
</span><span class="boring"> };
|
||||
</span><span class="boring"> };
|
||||
</span><span class="boring"> val
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">// ====================== FUTURE IMPLEMENTATION ==============================
|
||||
</span><span class="boring">#[derive(Clone)]
|
||||
</span><span class="boring">struct MyWaker {
|
||||
</span><span class="boring"> thread: thread::Thread,
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">#[derive(Clone)]
|
||||
</span><span class="boring">pub struct Task {
|
||||
</span><span class="boring"> id: usize,
|
||||
</span><span class="boring"> reactor: Arc<Mutex<Box<Reactor>>>,
|
||||
</span><span class="boring"> data: u64,
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">fn mywaker_wake(s: &MyWaker) {
|
||||
</span><span class="boring"> let waker_ptr: *const MyWaker = s;
|
||||
</span><span class="boring"> let waker_arc = unsafe { Arc::from_raw(waker_ptr) };
|
||||
</span><span class="boring"> waker_arc.thread.unpark();
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">fn mywaker_clone(s: &MyWaker) -> RawWaker {
|
||||
</span><span class="boring"> let arc = unsafe { Arc::from_raw(s) };
|
||||
</span><span class="boring"> std::mem::forget(arc.clone()); // increase ref count
|
||||
</span><span class="boring"> RawWaker::new(Arc::into_raw(arc) as *const (), &VTABLE)
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">const VTABLE: RawWakerVTable = unsafe {
|
||||
</span><span class="boring"> RawWakerVTable::new(
|
||||
</span><span class="boring"> |s| mywaker_clone(&*(s as *const MyWaker)), // clone
|
||||
</span><span class="boring"> |s| mywaker_wake(&*(s as *const MyWaker)), // wake
|
||||
</span><span class="boring"> |s| mywaker_wake(*(s as *const &MyWaker)), // wake by ref
|
||||
</span><span class="boring"> |s| drop(Arc::from_raw(s as *const MyWaker)), // decrease refcount
|
||||
</span><span class="boring"> )
|
||||
</span><span class="boring">};
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">fn waker_into_waker(s: *const MyWaker) -> Waker {
|
||||
</span><span class="boring"> let raw_waker = RawWaker::new(s as *const (), &VTABLE);
|
||||
</span><span class="boring"> unsafe { Waker::from_raw(raw_waker) }
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">impl Task {
|
||||
</span><span class="boring"> fn new(reactor: Arc<Mutex<Box<Reactor>>>, data: u64, id: usize) -> Self {
|
||||
</span><span class="boring"> Task { id, reactor, data }
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">impl Future for Task {
|
||||
</span><span class="boring"> type Output = usize;
|
||||
</span><span class="boring"> fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
</span><span class="boring"> let mut r = self.reactor.lock().unwrap();
|
||||
</span><span class="boring"> if r.is_ready(self.id) {
|
||||
</span><span class="boring"> println!("POLL: TASK {} IS READY", self.id);
|
||||
</span><span class="boring"> *r.tasks.get_mut(&self.id).unwrap() = TaskState::Finished;
|
||||
</span><span class="boring"> Poll::Ready(self.id)
|
||||
</span><span class="boring"> } else if r.tasks.contains_key(&self.id) {
|
||||
</span><span class="boring"> println!("POLL: REPLACED WAKER FOR TASK: {}", self.id);
|
||||
</span><span class="boring"> r.tasks.insert(self.id, TaskState::NotReady(cx.waker().clone()));
|
||||
</span><span class="boring"> Poll::Pending
|
||||
</span><span class="boring"> } else {
|
||||
</span><span class="boring"> println!("POLL: REGISTERED TASK: {}, WAKER: {:?}", self.id, cx.waker());
|
||||
</span><span class="boring"> r.register(self.data, cx.waker().clone(), self.id);
|
||||
</span><span class="boring"> Poll::Pending
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">// =============================== REACTOR ===================================
|
||||
</span><span class="boring">enum TaskState {
|
||||
</span><span class="boring"> Ready,
|
||||
</span><span class="boring"> NotReady(Waker),
|
||||
</span><span class="boring"> Finished,
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">struct Reactor {
|
||||
</span><span class="boring"> dispatcher: Sender<Event>,
|
||||
</span><span class="boring"> handle: Option<JoinHandle<()>>,
|
||||
</span><span class="boring"> tasks: HashMap<usize, TaskState>,
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">#[derive(Debug)]
|
||||
</span><span class="boring">enum Event {
|
||||
</span><span class="boring"> Close,
|
||||
</span><span class="boring"> Timeout(u64, usize),
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">impl Reactor {
|
||||
</span><span class="boring"> fn new() -> Arc<Mutex<Box<Self>>> {
|
||||
</span><span class="boring"> let (tx, rx) = channel::<Event>();
|
||||
</span><span class="boring"> let reactor = Arc::new(Mutex::new(Box::new(Reactor {
|
||||
</span><span class="boring"> dispatcher: tx,
|
||||
</span><span class="boring"> handle: None,
|
||||
</span><span class="boring"> tasks: HashMap::new(),
|
||||
</span><span class="boring"> })));
|
||||
</span><span class="boring">
|
||||
</span><span class="boring"> let reactor_clone = Arc::downgrade(&reactor);
|
||||
</span><span class="boring"> let handle = thread::spawn(move || {
|
||||
</span><span class="boring"> let mut handles = vec![];
|
||||
</span><span class="boring"> // This simulates some I/O resource
|
||||
</span><span class="boring"> for event in rx {
|
||||
</span><span class="boring"> println!("REACTOR: {:?}", event);
|
||||
</span><span class="boring"> let reactor = reactor_clone.clone();
|
||||
</span><span class="boring"> match event {
|
||||
</span><span class="boring"> Event::Close => break,
|
||||
</span><span class="boring"> Event::Timeout(duration, id) => {
|
||||
</span><span class="boring"> let event_handle = thread::spawn(move || {
|
||||
</span><span class="boring"> thread::sleep(Duration::from_secs(duration));
|
||||
</span><span class="boring"> let reactor = reactor.upgrade().unwrap();
|
||||
</span><span class="boring"> reactor.lock().map(|mut r| r.wake(id)).unwrap();
|
||||
</span><span class="boring"> });
|
||||
</span><span class="boring"> handles.push(event_handle);
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring"> handles.into_iter().for_each(|handle| handle.join().unwrap());
|
||||
</span><span class="boring"> });
|
||||
</span><span class="boring"> reactor.lock().map(|mut r| r.handle = Some(handle)).unwrap();
|
||||
</span><span class="boring"> reactor
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring">
|
||||
</span><span class="boring"> fn wake(&mut self, id: usize) {
|
||||
</span><span class="boring"> self.tasks.get_mut(&id).map(|state| {
|
||||
</span><span class="boring"> match mem::replace(state, TaskState::Ready) {
|
||||
</span><span class="boring"> TaskState::NotReady(waker) => waker.wake(),
|
||||
</span><span class="boring"> TaskState::Finished => panic!("Called 'wake' twice on task: {}", id),
|
||||
</span><span class="boring"> _ => unreachable!()
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring"> }).unwrap();
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring">
|
||||
</span><span class="boring"> fn register(&mut self, duration: u64, waker: Waker, id: usize) {
|
||||
</span><span class="boring"> if self.tasks.insert(id, TaskState::NotReady(waker)).is_some() {
|
||||
</span><span class="boring"> panic!("Tried to insert a task with id: '{}', twice!", id);
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring"> self.dispatcher.send(Event::Timeout(duration, id)).unwrap();
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring">
|
||||
</span><span class="boring"> fn close(&mut self) {
|
||||
</span><span class="boring"> self.dispatcher.send(Event::Close).unwrap();
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring">
|
||||
</span><span class="boring"> fn is_ready(&self, id: usize) -> bool {
|
||||
</span><span class="boring"> self.tasks.get(&id).map(|state| match state {
|
||||
</span><span class="boring"> TaskState::Ready => true,
|
||||
</span><span class="boring"> _ => false,
|
||||
</span><span class="boring"> }).unwrap_or(false)
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring">}
|
||||
</span><span class="boring">
|
||||
</span><span class="boring">impl Drop for Reactor {
|
||||
</span><span class="boring"> fn drop(&mut self) {
|
||||
</span><span class="boring"> self.handle.take().map(|h| h.join().unwrap()).unwrap();
|
||||
</span><span class="boring"> }
|
||||
</span><span class="boring">}
|
||||
</span></code></pre></pre>
|
||||
# // ============================= 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));
|
||||
# let mut cx = Context::from_waker(&waker);
|
||||
#
|
||||
# // SAFETY: we shadow `future` so it can't be accessed again.
|
||||
# let mut future = unsafe { Pin::new_unchecked(&mut future) };
|
||||
# let val = loop {
|
||||
# match Future::poll(future.as_mut(), &mut cx) {
|
||||
# Poll::Ready(val) => break val,
|
||||
# Poll::Pending => thread::park(),
|
||||
# };
|
||||
# };
|
||||
# val
|
||||
# }
|
||||
#
|
||||
# // ====================== FUTURE IMPLEMENTATION ==============================
|
||||
# #[derive(Clone)]
|
||||
# struct MyWaker {
|
||||
# thread: thread::Thread,
|
||||
# }
|
||||
#
|
||||
# #[derive(Clone)]
|
||||
# pub struct Task {
|
||||
# id: usize,
|
||||
# reactor: Arc<Mutex<Box<Reactor>>>,
|
||||
# data: u64,
|
||||
# }
|
||||
#
|
||||
# fn mywaker_wake(s: &MyWaker) {
|
||||
# let waker_ptr: *const MyWaker = s;
|
||||
# let waker_arc = unsafe { Arc::from_raw(waker_ptr) };
|
||||
# waker_arc.thread.unpark();
|
||||
# }
|
||||
#
|
||||
# fn mywaker_clone(s: &MyWaker) -> RawWaker {
|
||||
# let arc = unsafe { Arc::from_raw(s) };
|
||||
# std::mem::forget(arc.clone()); // increase ref count
|
||||
# RawWaker::new(Arc::into_raw(arc) as *const (), &VTABLE)
|
||||
# }
|
||||
#
|
||||
# const VTABLE: RawWakerVTable = unsafe {
|
||||
# RawWakerVTable::new(
|
||||
# |s| mywaker_clone(&*(s as *const MyWaker)), // clone
|
||||
# |s| mywaker_wake(&*(s as *const MyWaker)), // wake
|
||||
# |s| mywaker_wake(*(s as *const &MyWaker)), // wake by ref
|
||||
# |s| drop(Arc::from_raw(s as *const MyWaker)), // decrease refcount
|
||||
# )
|
||||
# };
|
||||
#
|
||||
# fn waker_into_waker(s: *const MyWaker) -> Waker {
|
||||
# let raw_waker = RawWaker::new(s as *const (), &VTABLE);
|
||||
# unsafe { Waker::from_raw(raw_waker) }
|
||||
# }
|
||||
#
|
||||
# impl Task {
|
||||
# fn new(reactor: Arc<Mutex<Box<Reactor>>>, data: u64, id: usize) -> Self {
|
||||
# Task { id, reactor, data }
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# impl Future for Task {
|
||||
# type Output = usize;
|
||||
# fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
# let mut r = self.reactor.lock().unwrap();
|
||||
# if r.is_ready(self.id) {
|
||||
# println!("POLL: TASK {} IS READY", self.id);
|
||||
# *r.tasks.get_mut(&self.id).unwrap() = TaskState::Finished;
|
||||
# Poll::Ready(self.id)
|
||||
# } else if r.tasks.contains_key(&self.id) {
|
||||
# println!("POLL: REPLACED WAKER FOR TASK: {}", self.id);
|
||||
# r.tasks.insert(self.id, TaskState::NotReady(cx.waker().clone()));
|
||||
# Poll::Pending
|
||||
# } else {
|
||||
# println!("POLL: REGISTERED TASK: {}, WAKER: {:?}", self.id, cx.waker());
|
||||
# r.register(self.data, cx.waker().clone(), self.id);
|
||||
# Poll::Pending
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# // =============================== REACTOR ===================================
|
||||
# enum TaskState {
|
||||
# Ready,
|
||||
# NotReady(Waker),
|
||||
# Finished,
|
||||
# }
|
||||
# struct Reactor {
|
||||
# dispatcher: Sender<Event>,
|
||||
# handle: Option<JoinHandle<()>>,
|
||||
# tasks: HashMap<usize, TaskState>,
|
||||
# }
|
||||
#
|
||||
# #[derive(Debug)]
|
||||
# enum Event {
|
||||
# Close,
|
||||
# Timeout(u64, usize),
|
||||
# }
|
||||
#
|
||||
# impl Reactor {
|
||||
# fn new() -> Arc<Mutex<Box<Self>>> {
|
||||
# let (tx, rx) = channel::<Event>();
|
||||
# let reactor = Arc::new(Mutex::new(Box::new(Reactor {
|
||||
# dispatcher: tx,
|
||||
# handle: None,
|
||||
# tasks: HashMap::new(),
|
||||
# })));
|
||||
#
|
||||
# let reactor_clone = Arc::downgrade(&reactor);
|
||||
# let handle = thread::spawn(move || {
|
||||
# let mut handles = vec![];
|
||||
# // This simulates some I/O resource
|
||||
# for event in rx {
|
||||
# println!("REACTOR: {:?}", event);
|
||||
# let reactor = reactor_clone.clone();
|
||||
# match event {
|
||||
# Event::Close => break,
|
||||
# Event::Timeout(duration, id) => {
|
||||
# let event_handle = thread::spawn(move || {
|
||||
# thread::sleep(Duration::from_secs(duration));
|
||||
# let reactor = reactor.upgrade().unwrap();
|
||||
# reactor.lock().map(|mut r| r.wake(id)).unwrap();
|
||||
# });
|
||||
# handles.push(event_handle);
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# handles.into_iter().for_each(|handle| handle.join().unwrap());
|
||||
# });
|
||||
# reactor.lock().map(|mut r| r.handle = Some(handle)).unwrap();
|
||||
# reactor
|
||||
# }
|
||||
#
|
||||
# fn wake(&mut self, id: usize) {
|
||||
# self.tasks.get_mut(&id).map(|state| {
|
||||
# match mem::replace(state, TaskState::Ready) {
|
||||
# TaskState::NotReady(waker) => waker.wake(),
|
||||
# TaskState::Finished => panic!("Called 'wake' twice on task: {}", id),
|
||||
# _ => unreachable!()
|
||||
# }
|
||||
# }).unwrap();
|
||||
# }
|
||||
#
|
||||
# fn register(&mut self, duration: u64, waker: Waker, id: usize) {
|
||||
# if self.tasks.insert(id, TaskState::NotReady(waker)).is_some() {
|
||||
# panic!("Tried to insert a task with id: '{}', twice!", id);
|
||||
# }
|
||||
# self.dispatcher.send(Event::Timeout(duration, id)).unwrap();
|
||||
# }
|
||||
#
|
||||
# fn close(&mut self) {
|
||||
# self.dispatcher.send(Event::Close).unwrap();
|
||||
# }
|
||||
#
|
||||
# fn is_ready(&self, id: usize) -> bool {
|
||||
# self.tasks.get(&id).map(|state| match state {
|
||||
# TaskState::Ready => true,
|
||||
# _ => false,
|
||||
# }).unwrap_or(false)
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# impl Drop for Reactor {
|
||||
# fn drop(&mut self) {
|
||||
# self.handle.take().map(|h| h.join().unwrap()).unwrap();
|
||||
# }
|
||||
# }
|
||||
</code></pre></pre>
|
||||
<p>I added a some debug printouts so we can observe a couple of things:</p>
|
||||
<ol>
|
||||
<li>How the <code>Waker</code> object looks just like the <em>trait object</em> we talked about in an earlier chapter</li>
|
||||
@@ -981,18 +978,6 @@ improvement which you can explore further if you wish.</p>
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
window.playpen_line_numbers = true;
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
window.playpen_copyable = true;
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<script src="ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="editor.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="mode-rust.js" type="text/javascript" charset="utf-8"></script>
|
||||
|
||||
Reference in New Issue
Block a user