Terminates the worker. The pending tasks can be allowed to finish by passing finishPendingTasks as true. If false is passed, the worker is terminated immediately.
Returns a future which resolves when the worker has been terminated.
Note that the future blocks the calling thread. So a rogue scheduled task may hang the calling thread infinitely if finishPendingTasks is true.