terminate worker threads after they are finished

Each worker thread should be terminated after it finishes processing the image, otherwise the browser keeps it alive and eventually the script hits the maximum concurrent worker limit.