Skip to content

Instantly share code, notes, and snippets.

@gauntface
Created March 6, 2017 22:15
Show Gist options
  • Select an option

  • Save gauntface/5a4ad9e589d46718fe0a5e44203fcf3e to your computer and use it in GitHub Desktop.

Select an option

Save gauntface/5a4ad9e589d46718fe0a5e44203fcf3e to your computer and use it in GitHub Desktop.
return new Promise((resolve, reject) => {
const event = new FetchEvent('fetch', {
request: new Request('/index.html'),
});
event.respondWith = (promiseChain) => {
if (promiseChain) {
// Check if promise was returned - otherise
// it could be a response
if (promiseChain instanceof Promise) {
promiseChain.then(resolve, reject);
} else {
resolve(promiseChain);
}
return;
}
resolve();
};
self.dispatchEvent(event);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment