You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to discuss on the Mozilla's use case w3c/ServiceWorker#678 (comment) from n.c's perspective. I'm not insisting on making this particular use case as an n.c's use case, but would like to think about some related points more generally.
The SW on sync event tries to request a separate processing job to a shared worker.
So basically, the SW is a client and the shared worker is a service here.
There's no way to use (connect to) a shared worker/worker from a service worker now.
No clear lifetime binding between a service worker and a shared worker is suggested yet.
Assuming the background job the shared worker does could ever be written as a service worker code (yes it's controversial and we may have to confine the case to those can live with waitUntil(p)), it'll be like:
// in service worker that handles background sync notificationsself.onsync=function(event){if(event.registration.id==="periodicSync"){event.waitUntil(newPromise(resolve,reject){// The service now connects to will connect to the email servers // and syncs data to IDB.
navigator.connect("https://example.com/email-sync").then(function(port){// request sync to the serviceport.postMessage({type: 'sync'});// Listen for a message from the service// This port is persistent so this listener can be invoked // when the SW is terminated and spun up again.port.onmessage=function(e){vardata=e.data;if(data.type==='syncComplete'){// The service completed. }};// Resolve the waitUntil() promise here. This SW can be terminated // whenever from this point.resolve();});});}};
The service can be cross-origin service worker for sure as well as one in the same-origin as in this case.
The text was updated successfully, but these errors were encountered:
I'd like to discuss on the Mozilla's use case w3c/ServiceWorker#678 (comment) from
n.c
's perspective. I'm not insisting on making this particular use case as ann.c
's use case, but would like to think about some related points more generally.sync
event tries to request a separate processing job to a shared worker.new SharedWorker("email-worker.js")
as in the example in Workers & SharedWorkers within ServiceWorkers w3c/ServiceWorker#678 (comment), the shared ports between the SW and the shared worker will not be guaranteed to be persistent until the job completes.Assuming the background job the shared worker does could ever be written as a service worker code (yes it's controversial and we may have to confine the case to those can live with
waitUntil(p)
), it'll be like:The service can be cross-origin service worker for sure as well as one in the same-origin as in this case.
The text was updated successfully, but these errors were encountered: