-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event for worker termination #5869
Comments
@hiroshige-g may be interested. |
My interest is test-only (to write a couple of worker termination WPTs). |
There is interest from Deno users on this topic. Node also implements a similar |
I'm supportive of this proposal if there are valid use cases in real applications. This will also help us to write more solid WPTs as @hiroshige-g mentioned. I'm curious how this event should behave on close of the owner context, that is, unload of the parent document or termination of the parent worker. Do we want to guarantee that the event is always fired before the context close? IMHO I think we shouldn't guarantee that as it will degrade navigation performance. On the other hand, this will impair the reliability of the event and may not satisfy some of the use cases. |
A worker doesn't survive for long if its parent document has closed; see the "closing orphan workers" step in the worker event loop. And while the behavior of nested dedicated workers when their dedicated worker parent dies is not very clear in the spec, implementations also don't keep the nested worker alive for long (see #7840). So it doesn't seem like this is worth worrying about too much. |
@andreubotella What about shared workers? There could be several windows referencing same worker. |
The
AbstractWorker
mixin provides anonerror
prop to get notified when the worker throws. However, graceful or forced termination is not detectable right now.I have found a bunch of situations where I’d like to be notified when a worker is being terminated. In my head, all of these are desired sources for this notification:
DedicatedWorkerGlobalScope.close()
SharedWorkerGlobalScope.close()
Worker.terminate()
Proposal: Expose an
onterminate
prop (and/orterminate
event) toAbstractWorker
.The text was updated successfully, but these errors were encountered: