add terminated event to prime.js to stop the loop in the background when the worker is shutdown