DEV Community

Rust futures: an uneducated, short and hopefully not boring tutorial - Part 3 - The reactor

Francesco Cogno on November 08, 2017

Intro In this post we will try and explain how the reactor works. In the previous posts we used it extensively to execute our futures bu...
Collapse
 
inzanez profile image
inzanez

Hi

many thanks for that tutorial, really interesting! I just got one question:

You state the reactor parks our future in case we return

Ok(Async::NotReady)

But here, you seem to notify the reactor to unpark before we return Ok(Async::NotReady):

println!("not ready yet --> {:?}", self);
futures::task::current().notify();
Ok(Async::NotReady)

So the reactor gets a notification to unpark something that's not yet been parked, doesn't it? ;-)

Collapse
 
mindflavor profile image
Francesco Cogno

Ah yes it's true.
It's an horrible way of simulating the external unpark command :)

Ideally this command should be issued by another "entity" (for example the OS in case of async IO).