TLDR: What is an alternative to WorkerGlobalScope.close()
which is not deprecated
I want to close/stop/terminate a Javascript web worker from the inside, after its job is done, since there is a setInterval()
which keeps being active even after the main work is done.
Reading this SO question (JavaScript Web Worker - close() vs terminate()), it seems like self.close()
is what I'm searching for. But apparently this is deprecated (stated here) without any mention of alternatives.
The only alternative I have come up with so far would be to send a message to the main thread which then invokes a worker.terminate()
call, but that seems like overkill since I would then need to check every message that comes this way for a termination request.
Am I missing something? What should I use?