Re: [ServiceWorker] When does the openWindow promise resolve? (#728)

Isn't the sync between listener setup and sender's posting a message between different threads rather a general case? I'm not sure whether a snippet below could help? /cc @jakearchibald 

```js
// Page
navigator.serviceWorker.addEventListener('message', function (e) {
    console.log('got message:', e.data);
});

document.addEventListener('DOMContentLoaded', e => {
  var controller = navigator.serviceWorker.controller;
  if (controller)
    controller.postMessage('clientloaded');
})

// SW
var client_id;
clients.openWindow(url).then(c => { client_id = c.id; });

self.onmessage = e => {
  if (e.data == 'clientloaded') {
    clients.matchAll().then(clients => {
      clients.forEach(c => {
        if (c.id == client_id) {
          c.postMessage('fromnotificationclick');
        }
      });
    });
  }
};
```

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/728#issuecomment-132118359

Received on Tuesday, 18 August 2015 08:23:47 UTC