doc: improve worker pool example
Checklist
-
documentation is changed or added -
commit message follows commit guidelines
In the worker pool example, the kWorkerFreedEvent
should be emitted in case of error as well. After adding new worker in the error handler, the pending tasks should be notified of an available worker.
For instance, assume that we create a worker pool with two workers. Then we call runTask
thrice such that the first two tasks are still running when it's called for the third time. As a result, the third task will be enqueued and wait for a kWorkerFreedEvent
. Now suppose that both of the first two tasks throw an error. In response, our error handler replaces the two existing workers with new ones. But if kWorkerFreedEvent
is not emitted after replacing the workers, the third task which was enqueued will never (assuming no more tasks are added after that) know of an available worker and hence will never run.