Description
Hi folks,
I'm using LocalPool
and run_until_stalled
to be able to run the executor and reactor in the same thread. Basically I have a loop that goes something like:
loop {
pool.run_until_stalled();
reactor.poll();
}
In other words, when no tasks can make progress, the reactor blocks until new I/O events arrive and wakers are triggered. Then the tasks are resumed again.
The only issue with this is I couldn't find a simple way to know when all tasks have completed in order to break out of the loop. It would be nice if there were a method on LocalPool
to check if there any tasks left to run.
For now what I'm doing is passing around a shared counter value, that is incremented near all spawn calls and decremented near the end of all tasks. And if that value is zero after calling run_until_stalled
then the code breaks out of the loop (and makes a call to run
for good measure). But this is quite messy.