Im trying to build a service worker for managing a multi window app. Many of the state for doing this i can save in the caches, which is fine, but im finding that i'd also need to for example save functions.
Use case:
I save information related to some window, when this window refreshes, im sending a post on the beforeunload event (to the worker) so it knows the window is disconnecting, I'd like to fire a race between a timeout and a new fetch event done by the same clientId (so i know its back), if the timeout wins, i can propagate the disconnection of that window, if the fetch wins, i know the window is back, and i can issue a reconnect between affected windows.
Normally, i would have a scoped variable (some sort of map), and save it there, but i dont really know how service workers do their pausing (i dont fully understand the waitUntil).
My thinking is that they do some sort of dump of the whole memory? and re start it if some event needs to be handled? or do services workers just run all the time and i can keep variables laying around?
im ok if this scope is not shared between different versions of the worker, but can i safely do this? i guess i would need to put that race in the waitUntil?