Open BairDev opened 7 years ago
@BairDev I am the one who wrote that answer on stackoverflow. Actually, i just found that problem when i try to just send response through message channel. But I am kind of understand why the specification that do not write define the behavior you mentioned.
So after all, I suggest you to consider backgroundSync as a message of online in backstage.Though in specification, i define itself as method to synchronize data, but what i think is, synchronize data is not equal to send a request.
@toxic-johann Thanks for your response. You are right, I just realized, that I was not aware of the acutal meaning of background sync. There is no data sharing between app and SW involved. When I wrote that issue I just wondered, why the two promises are not chained at all: the one in the custom function, which is called in event.waitUntil()
, and the one from registration.snyc.register('my-tag')
. It would be interesting to know a bit more about the technical background here.
@BairDev hmmm……That's a good question.
I just write the promise in sendMeesageToSw
for the page to communicate with worker.So that i can wait until i get the response.
The event.waitUntil()
is used to extend the life time of event, in order to make the worker not to be terminated.
Stupid Question, Derived from Confusion
While playing with a Service Worker and especially with the
sync
feature/event, I've noticed, that the event listener for the sync event or, more precisely, the promise in the custom methodreturnAPromise
in theevent.waitUntil()
line of, sayis not allowed to return any data (did not try it with a primitive value though). Those would appear in the callback of the promise in the app, like here:
I've found this hint here:
Even this hint is not related to the behavior of the sync feature, but to the type of data, which can be sent over some kind of messaging system (two way communication between the app and the SW).
Regarding this: You can create a workaround with a
MessageChannel
, which is also demonstrated by this example. but an approach like this one, in which the app tries to get the fetched data directly won't ever work as far as I know.Now, I've looked here and there for a specification of this behavior, but did not find much. Even in this section (5.3: SyncEvent) of the spec nothing indicates, that sharing the data between the app and the SW is not allowed for synchronization tasks (in contrast to intercepting requests with the very same SW for example).
Is there any reason, why this is not specified and not explained anywhere?