When does the web worker create a new thread?
Does the web worker create a new thread when a new web worker is created by calling its constructor with a js file?
Or is a new thread created every time I call postMessage
?
I basically need to know if I can generate new threads for an existing web worker.
As far as the spec is concerned , a "separate thread or process or equivalent construct" is created when a worker is created, and then it has an event loop similar to the main thread's event loop in which type events occur message
.
Implementations are free to do what they want, albeit on condition that they conform to the semantics defined by the specification.
I basically need to know if I can generate new threads for an existing web worker.
If you mean that one worker has multiple threads running at the same time, the only way to do this is to call new Worker
more than once with the same script (which is absolutely the right thing to do), which of course is not one worker with multiple threads, but rather two workers executing the same code, each with one thread.