{"action":"created","issue":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/935","repository_url":"https://api.github.com/repos/slightlyoff/ServiceWorker","labels_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/935/labels{/name}","comments_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/935/comments","events_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/935/events","html_url":"https://github.com/slightlyoff/ServiceWorker/issues/935","id":167952378,"number":935,"title":"should async waitUntil() work in .then() handler of promise passed to previous waitUntil()?","user":{"login":"wanderview","id":1256526,"avatar_url":"https://avatars.githubusercontent.com/u/1256526?v=3","gravatar_id":"","url":"https://api.github.com/users/wanderview","html_url":"https://github.com/wanderview","followers_url":"https://api.github.com/users/wanderview/followers","following_url":"https://api.github.com/users/wanderview/following{/other_user}","gists_url":"https://api.github.com/users/wanderview/gists{/gist_id}","starred_url":"https://api.github.com/users/wanderview/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wanderview/subscriptions","organizations_url":"https://api.github.com/users/wanderview/orgs","repos_url":"https://api.github.com/users/wanderview/repos","events_url":"https://api.github.com/users/wanderview/events{/privacy}","received_events_url":"https://api.github.com/users/wanderview/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/labels/decided","name":"decided","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/milestones/2","html_url":"https://github.com/slightlyoff/ServiceWorker/milestones/Version%201","labels_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/milestones/2/labels","id":746092,"number":2,"title":"Version 1","description":"","creator":{"login":"tobie","id":3392,"avatar_url":"https://avatars.githubusercontent.com/u/3392?v=3","gravatar_id":"","url":"https://api.github.com/users/tobie","html_url":"https://github.com/tobie","followers_url":"https://api.github.com/users/tobie/followers","following_url":"https://api.github.com/users/tobie/following{/other_user}","gists_url":"https://api.github.com/users/tobie/gists{/gist_id}","starred_url":"https://api.github.com/users/tobie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tobie/subscriptions","organizations_url":"https://api.github.com/users/tobie/orgs","repos_url":"https://api.github.com/users/tobie/repos","events_url":"https://api.github.com/users/tobie/events{/privacy}","received_events_url":"https://api.github.com/users/tobie/received_events","type":"User","site_admin":false},"open_issues":37,"closed_issues":152,"state":"open","created_at":"2014-08-07T10:50:36Z","updated_at":"2016-07-28T20:54:59Z","due_on":"2016-03-30T15:00:00Z","closed_at":null},"comments":4,"created_at":"2016-07-27T20:46:04Z","updated_at":"2016-07-29T11:38:22Z","closed_at":null,"body":"I'm currently implementing async `waitUntil()` in gecko.  The main intention here is to allow things like:\r\n\r\n```\r\naddEventListener('fetch', e => {\r\n  e.respondWith(fetch(e.request)).then(response => {\r\n    e.waitUntil(caches.open('db').then(cache => {\r\n      return cache.put(e.request, response);\r\n    });\r\n    return response.clone();\r\n  });\r\n});\r\n```\r\n\r\nSo you can call `waitUntil()` as long as there is an extension promise still unsettled.\r\n\r\nBut what about this non-idiomatic code:\r\n\r\n```\r\naddEventListener('fetch', e => {\r\n  let respondWithPromise = fetch(e.request);\r\n  respondWithPromise.then(response => {\r\n    let clone = response.clone();\r\n    e.waitUntil(caches.open('db').then(cache => {\r\n      return cache.put(e.request, clone);\r\n    });\r\n  });\r\n  e.respondWith(respondWithPromise);\r\n});\r\n```\r\n\r\nHere pass the `fetch()` promise directly to `respondWith()`.  Or additional caching code is also hung off this same `fetch()` promise.\r\n\r\nTechnically when the caching code runs the promise passed to `respondWith()` is settled, but if order of promise handlers is maintained then the `respondWith()` code has not been notified yet.\r\n\r\nI *think* this should probably work, but the spec text is a bit vague.  It says:\r\n\r\n> Wait until the result of waiting for all of extendLifetimePromises settles. \r\n\r\nDoes that respect ordering of promise handlers?\r\n\r\nConversely, if we call `respondWith()` before the `respondWithPromise.then()` above, then I think the `waitUntil` should throw.  The respondWith code would clear the extensions allowed flag before the caching code had a chance to run.\r\n\r\nAll this is corner casey, but I thought it would be good to clarify."},"comment":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/comments/236159091","html_url":"https://github.com/slightlyoff/ServiceWorker/issues/935#issuecomment-236159091","issue_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/935","id":236159091,"user":{"login":"jakearchibald","id":93594,"avatar_url":"https://avatars.githubusercontent.com/u/93594?v=3","gravatar_id":"","url":"https://api.github.com/users/jakearchibald","html_url":"https://github.com/jakearchibald","followers_url":"https://api.github.com/users/jakearchibald/followers","following_url":"https://api.github.com/users/jakearchibald/following{/other_user}","gists_url":"https://api.github.com/users/jakearchibald/gists{/gist_id}","starred_url":"https://api.github.com/users/jakearchibald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakearchibald/subscriptions","organizations_url":"https://api.github.com/users/jakearchibald/orgs","repos_url":"https://api.github.com/users/jakearchibald/repos","events_url":"https://api.github.com/users/jakearchibald/events{/privacy}","received_events_url":"https://api.github.com/users/jakearchibald/received_events","type":"User","site_admin":false},"created_at":"2016-07-29T11:38:22Z","updated_at":"2016-07-29T11:38:22Z","body":"Yep, I'm going to go through all the issues post F2F and make sure they're tagged properly and carry additional actions out"}}
{"actor":{"display_login":"jakearchibald"}}