| 18 | |
| 19 | impl Executor { |
| 20 | fn run(&self) { |
| 21 | while let Ok(task) = self.ready_queue.recv() { |
| 22 | // Take the future, and if it has not yet completed (is still Some), |
| 23 | // poll it in an attempt to complete it. |
| 24 | let mut future_slot = task.future.lock().unwrap(); |
| 25 | if let Some(mut future) = future_slot.take() { |
| 26 | // Create a `LocalWaker` from the task itself |
| 27 | let waker = waker_ref(&task); |
| 28 | let context = &mut Context::from_waker(&waker); |
| 29 | // `BoxFuture<T>` is a type alias for |
| 30 | // `Pin<Box<dyn Future<Output = T> + Send + 'static>>`. |
| 31 | // We can get a `Pin<&mut dyn Future + Send + 'static>` |
| 32 | // from it by calling the `Pin::as_mut` method. |
| 33 | if future.as_mut().poll(context).is_pending() { |
| 34 | // We're not done processing the future, so put it |
| 35 | // back in its task to be run again in the future. |
| 36 | *future_slot = Some(future); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /// `Spawner` spawns new futures onto the task channel. |