Description
Distilled from futureverse/future.callr#20:
Although rare, and probably a mistake, there are ways to end up with nbrOfFreeWorkers() == 0
, even when some of the active futures have been resolved. In such cases, code that rely on nbrOfFreeWorkers()
to decided whether to create another future might end up in a deadline, e.g.
if (nbrOfFreeWorkers() > 0) f <- future(...)
To account for such use as well, nbrOfFreeWorkers()
could attempt an internal cleanup of registered futures in case there are no free workers available. Only if there are no free workers after such a cleanup, it should return 0
. Note that the internal cleanup will not block; it will check if any of the registered futures are resolved, and if one is, then its results are collected, allowing us to remove that future from the internal registry freeing up one worker.
/ht @randy3k