Does the Tokio reactor poll all possible poll() functions between each combinator?

Viewed 122

A call to poll can never block, otherwise the entire thread the async core executes on will be blocked, stopping all possible causality until the blocking function returns.

I spawn a future onto the reactor, and there are a series of combinators like my_future.and_then(…).map(…).then(…).

The reactor polls the future, and then before it executes the next and_then combinator, does the reactor iterate through all other futures, checking to see if they are ready, or does the reactor follow through with all the combinatorial steps of my_future.and_then(…).map(…).then(…)?

I am asking this question because it is important to know how to design my program given the causality of the async core.

1 Answers

As far as the asynchronous executor knows, there aren't intermediate steps. Each combinator consumes the previous future, producing a brand new future. At the end, a single future is handed to the executor and it calls poll on that future as required.

It is up to each parent future to decide if and when any child futures are polled, but this can only happen when the parent future is polled.

See also:

Related