[whatwg] Terminate a Worker algorithm

Ian Hickson ian at hixie.ch
Tue Dec 16 02:47:13 PST 2008


On Tue, 16 Dec 2008, Alexey Proskuryakov wrote:
> 
> Dec 16, 2008, в 9:43 AM, Ian Hickson написал(а):
> 
> > > 1) The algorithm assumes that a WorkerGlobalScope exists, and 
> > > doesn't specify what happens if it is invoked before 
> > > WorkerGlobalScope is created (e.g. if the script is still being 
> > > loaded, or the scope is being created, but Worker.terminate() is 
> > > called from JS). I think that the right behavior is to re-invoke the 
> > > algorithm after the scope is created, because it may be too late to 
> > > prevent its creation.
> > 
> > It can't be invoked before the WorkerGlobalScope is created. The 
> > WorkerGlobalScope is created before the constructor returns the Worker 
> > object.
> 
> This means that creating a Worker would involve running a nested run 
> loop, waiting for WorkerGlobalScope to be created in another 
> thread/process. I think that WorkerGlobalScope needs to be created 
> asynchronously. The above is the only observable difference with 
> synchronous creation that I could find, so I think that requiring 
> synchronous operation is unnecessary.

Sure, implementation-wise there is a race condition to take care of. But 
the behavior to implement is well-defined.


> > > 2) Events in WorkerGlobalScope event queue are dropped when 
> > > terminating a worker, but messages posted to Worker are not. I think 
> > > that the expected behavior is that after calling Worker.terminate(), 
> > > no messages will be dispatched to worker's event listeners.
> > 
> > Once 'closing' is set to true, the queue discards any additional 
> > tasks.
> 
> There is no "closing" flag on the Worker object, it's only defined on 
> WorkerGlobalScope as far as I can see.

Oh I see what you're saying. Sorry, I misunderstood. I guess we could 
empty the queue of messages once a worker is terminated... Ok, done.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list