threads.js
threads.js copied to clipboard
Cannot terminate pool when there is an init timeout
I'm testing my error handling code. I forced a timeout of 100ms in spawn, which causes the expected error. Inside the try/finally, I call .terminate(true). With the debugger paused on the line that calls terminate, I see:

which is expected. Then I let the program complete, and I'm left with a hung debugger and the workers still alive:

I should note that this terminate logic works normally if the error is not an init timeout.
What are your thoughts on this?
Sorry, just saw that I didn't reply yet.
I am a bit puzzled regarding this statement:
I forced a timeout of 100ms in spawn, which causes the expected error. Inside the try/finally, I call
.terminate(true).
I imagine your code looks something like this:
try {
const thread = await spawn(new Worker("./path/to/worker"))
// …
} finally {
thread.terminate() // <--- ?!
}
Obviously, you cannot terminate a thread that is potentially not even initialized yet (if async spawn() call has not completed), so your code must look different. Can you shine some light on that?