Move high level code outside of the mutex lock in handleWorkerTasks.

See #777.
Store the updated emit count when waiting for worker tasks.

This avoids a potential 100% CPU loop while no worker tasks have been added (only happens if at least one worker task has already been started).
Avoid useless work when Libevent2ManualEvent.wait doesn't have to wait.