Open inexorabletash opened 6 years ago
Based on https://tc39.github.io/ecma262/#sec-agent-clusters agent termination appears to be a concept that exists, although not exactly precisely defined. Perhaps we just want to add a <dfn>
around "terminate" there and reference it from the predicate.
It might also be worth thinking about agent deactivation/activation (more vague concepts mentioned in that section) and suspension/waiting via Atomics.wait. Maybe no special reactions need to happen, but I thought it'd be worth checking.
Cool, thanks for the pointers @domenic !
I don't think agent termination is observable currently and we've explicitly decided against APIs exposing it for workers in the past (GC exposure concerns or some such). E.g., when you navigate a document it becomes inactive, but it might not necessarily be terminated. It's quite a bit more complex and if we actually want to expose anything there we'd need to do more digging.
ISTM it's implicitly exposed in a few cases already:
But yeah, we need to be explicit about our intent and spec appropriately if if we move forward here.
For ServiceWorker integration, I think it might make sense to invoke the agent integration logic that aborts all requests and releases all held locks if the Service Worker Has No Pending Events algorithm returns true at the same place the ServiceWorker spec invokes Try Activate we do in step 5.2 of ExtendableEvent when the last promise resolves.
Said another way, break all locks when the ServiceWorker becomes eligible for termination.
The idea here would be:
Sounds reasonable to me at first glance.
Want to toss up a PR?
Two cases need to be specified:
I don't know how to specify the "when an agent terminates" part. The association will need to be made explicit, but that part is simple.