[w3c/ServiceWorker] How do I get extendableEvent.waitUntil() to play nicely with async functions (#1237)

The `await` operator is a great way to clean up async code avoiding the "callback pyramid of doom" up until I ran into this case when I'm wrestling `waitUntil()` to wait for my async function to finish:
```javascript
self.addEventListener('install', async event => {
  var resolve, reject;
  event.waitUntil(
    new Promise((...callbacks) => {
      [resolve, reject] = callbacks;
    })
  );
  try {
    let cache = await caches.open(cacheName);
    await cache.addAll(cacheUrls);
    resolve();
  } catch (e) {
    reject(e);
  }
});
```
I would like access to the promise object made by the async function in order to dramatically clean up the code. For example:
```javascript
self.addEventListener('install', async event => {
  event.waitUntil(arguments.promise); // example access to the async function's promise
  let cache = await caches.open(cacheName);
  await cache.addAll(cacheUrls);
});
```
I know that I can create an async function and nest it inside the `waitUntil()` call but my request is to get access to the current promise in order to keep simple, concise, and highly readable procedural code and eliminate use of unnecessary nesting and anonymous functions.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1237

Received on Wednesday, 29 November 2017 09:08:50 UTC