Let's start by introducing the Future trait:Â
- Implementing the Future trait requires only three constraints: an Item type, an Error type, and a poll() function. The actual trait looks as follows:
pub trait Future {
type Item;
type Error;
fn poll(
&mut self,
cx: &mut Context
) -> Result<Async<Self::Item>, Self::Error>;
}
- The Poll<Self::Item, Self::Error> is a type that translates into Result<Async<T>, E> , where T = Item and E = Error. This is what our example is using on line 50.
- poll() is called upon whenever a futures::task::Waker (can also be known as a Task) is executed with one of our executors located at futures::executor, or manually woken up by building a futures::task::Context and running with a future wrapper such as futures::future::poll_fn.
Now, onto our local_until() function:
- LocalPool offers us...