workbox-strategies
Advanced tools
Comparing version 6.0.0-alpha.3 to 6.0.0-rc.0
"use strict"; | ||
// @ts-ignore | ||
try { | ||
self['workbox:strategies:6.0.0-alpha.2'] && _(); | ||
self['workbox:strategies:6.0.0-alpha.3'] && _(); | ||
} | ||
catch (e) { } |
@@ -24,3 +24,3 @@ this.workbox = this.workbox || {}; | ||
try { | ||
self['workbox:strategies:6.0.0-alpha.2'] && _(); | ||
self['workbox:strategies:6.0.0-alpha.3'] && _(); | ||
} catch (e) {} | ||
@@ -1293,2 +1293,16 @@ | ||
/** | ||
* @param {Object} [options] | ||
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins} | ||
* to use in conjunction with this caching strategy. | ||
* @param {Object} [options.fetchOptions] Values passed along to the | ||
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) | ||
* of all fetch() requests made by this strategy. | ||
* @param {number} [options.networkTimeoutSeconds] If set, any network requests | ||
* that fail to respond within the timeout will result in a network error. | ||
*/ | ||
constructor(options = {}) { | ||
super(options); | ||
this._networkTimeoutSeconds = options.networkTimeoutSeconds || 0; | ||
} | ||
/** | ||
* @private | ||
@@ -1300,2 +1314,4 @@ * @param {Request|string} request A request to run this strategy for. | ||
*/ | ||
async _handle(request, handler) { | ||
@@ -1306,3 +1322,3 @@ { | ||
className: this.constructor.name, | ||
funcName: 'handle', | ||
funcName: '_handle', | ||
paramName: 'request' | ||
@@ -1312,7 +1328,18 @@ }); | ||
let error; | ||
let error = undefined; | ||
let response; | ||
try { | ||
response = await handler.fetch(request); | ||
const promises = [handler.fetch(request)]; | ||
if (this._networkTimeoutSeconds) { | ||
const timeoutPromise = timeout_js.timeout(this._networkTimeoutSeconds * 1000); | ||
promises.push(timeoutPromise); | ||
} | ||
response = await Promise.race(promises); | ||
if (!response) { | ||
throw new Error(`Timed out the network response after ` + `${this._networkTimeoutSeconds} seconds.`); | ||
} | ||
} catch (err) { | ||
@@ -1319,0 +1346,0 @@ error = err; |
@@ -1,2 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.strategies=function(t,e,s,r,a,i,n,o,c){"use strict";function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t}).apply(this,arguments)}try{self["workbox:strategies:6.0.0-alpha.2"]&&_()}catch(t){}function l(t){return"string"==typeof t?new Request(t):t}class u{constructor(t,e){this.t={},Object.assign(this,e),this.event=e.event,this.i=t,this.o=new n.Deferred,this.h=[],this.l=[...t.plugins],this.u=new Map;for(const t of this.l)this.u.set(t,{});this.event.waitUntil(this.o.promise)}fetch(t){return this.waitUntil((async()=>{const{event:e}=this;let r=l(t);if("navigate"===r.mode&&e instanceof FetchEvent&&e.preloadResponse){const t=await e.preloadResponse;if(t)return t}const a=this.hasCallback("fetchDidFail")?r.clone():null;try{for(const t of this.iterateCallbacks("requestWillFetch"))r=await t({request:r.clone(),event:e})}catch(t){throw new s.WorkboxError("plugin-error-request-will-fetch",{thrownError:t})}const i=r.clone();try{let t;t=await fetch(r,"navigate"===r.mode?void 0:this.i.fetchOptions);for(const s of this.iterateCallbacks("fetchDidSucceed"))t=await s({event:e,request:i,response:t});return t}catch(t){throw a&&await this.runCallbacks("fetchDidFail",{error:t,event:e,originalRequest:a.clone(),request:i.clone()}),t}})())}async fetchAndCachePut(t){const e=await this.fetch(t),s=e.clone();return this.waitUntil(this.cachePut(t,s)),e}cacheMatch(t){return this.waitUntil((async()=>{const e=l(t);let s;const{cacheName:r,matchOptions:a}=this.i,i=await this.getCacheKey(e,"read"),n=h({},a,{cacheName:r});s=await caches.match(i,n);for(const t of this.iterateCallbacks("cachedResponseWillBeUsed"))s=await t({cacheName:r,matchOptions:a,cachedResponse:s,request:i,event:this.event})||void 0;return s})())}async cachePut(t,e){const r=l(t);await c.timeout(0);const n=await this.getCacheKey(r,"write");if(!e)throw new s.WorkboxError("cache-put-with-no-response",{url:a.getFriendlyURL(n.url)});const h=await this.p(e);if(!h)return;const{cacheName:u,matchOptions:w}=this.i,f=await self.caches.open(u),d=this.hasCallback("cacheDidUpdate"),p=d?await i.cacheMatchIgnoreParams(f,n.clone(),["__WB_REVISION__"],w):null;try{await f.put(n,d?h.clone():h)}catch(t){throw"QuotaExceededError"===t.name&&await o.executeQuotaErrorCallbacks(),t}for(const t of this.iterateCallbacks("cacheDidUpdate"))await t({cacheName:u,oldResponse:p,newResponse:h.clone(),request:n,event:this.event})}async getCacheKey(t,e){if(!this.t[e]){let s=t;for(const t of this.iterateCallbacks("cacheKeyWillBeUsed"))s=l(await t({mode:e,request:s,event:this.event,params:this.params}));this.t[e]=s}return this.t[e]}hasCallback(t){for(const e of this.i.plugins)if(t in e)return!0;return!1}async runCallbacks(t,e){for(const s of this.iterateCallbacks(t))await s(e)}*iterateCallbacks(t){for(const e of this.i.plugins)if("function"==typeof e[t]){const s=this.u.get(e),r=r=>{const a=h({},r,{state:s});return e[t](a)};yield r}}waitUntil(t){return this.h.push(t),t}async doneWaiting(){let t;for(;t=this.h.shift();)await t}destroy(){this.o.resolve()}async p(t){let e=t,s=!1;for(const t of this.iterateCallbacks("cacheWillUpdate"))if(e=await t({request:this.request,response:e,event:this.event})||void 0,s=!0,!e)break;return s||e&&200!==e.status&&(e=void 0),e}}class w{constructor(t={}){this.cacheName=r.cacheNames.getRuntimeName(t.cacheName),this.plugins=t.plugins||[],this.fetchOptions=t.fetchOptions,this.matchOptions=t.matchOptions}handle(t){const[e]=this.handleAll(t);return e}handleAll(t){t instanceof FetchEvent&&(t={event:t,request:t.request});const e=t.event,s="string"==typeof t.request?new Request(t.request):t.request,r="params"in t?t.params:void 0,a=new u(this,{event:e,request:s,params:r}),i=this.v(a,s,e);return[i,this.m(i,a,s,e)]}async v(t,e,r){await t.runCallbacks("handlerWillStart",{event:r,request:e});let a=void 0;try{if(a=await this.q(e,t),!a||"error"===a.type)throw new s.WorkboxError("no-response",{url:e.url})}catch(s){for(const i of t.iterateCallbacks("handlerDidError"))if(a=await i({error:s,event:r,request:e}),a)break;if(!a)throw s}for(const s of t.iterateCallbacks("handlerWillRespond"))a=await s({event:r,request:e,response:a});return a}async m(t,e,s,r){let a,i;try{a=await t}catch(i){}try{await e.runCallbacks("handlerDidRespond",{event:r,request:s,response:a}),await e.doneWaiting()}catch(t){i=t}if(await e.runCallbacks("handlerDidComplete",{event:r,request:s,response:a,error:i}),e.destroy(),i)throw i}}const f={cacheWillUpdate:async({response:t})=>200===t.status||0===t.status?t:null};return t.CacheFirst=class extends w{async q(t,e){let r,a=await e.cacheMatch(t);if(!a)try{a=await e.fetchAndCachePut(t)}catch(t){r=t}if(!a)throw new s.WorkboxError("no-response",{url:t.url,error:r});return a}},t.CacheOnly=class extends w{async q(t,e){const r=await e.cacheMatch(t);if(!r)throw new s.WorkboxError("no-response",{url:t.url});return r}},t.NetworkFirst=class extends w{constructor(t={}){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f),this._=t.networkTimeoutSeconds||0}async q(t,e){const r=[],a=[];let i;if(this._){const{id:s,promise:n}=this.g({request:t,logs:r,handler:e});i=s,a.push(n)}const n=this.k({timeoutId:i,request:t,logs:r,handler:e});a.push(n);for(const t of a)e.waitUntil(t);let o=await Promise.race(a);if(o||(o=await n),!o)throw new s.WorkboxError("no-response",{url:t.url});return o}g({request:t,logs:e,handler:s}){let r;return{promise:new Promise((e=>{r=setTimeout((async()=>{e(await s.cacheMatch(t))}),1e3*this._)})),id:r}}async k({timeoutId:t,request:e,logs:s,handler:r}){let a,i;try{i=await r.fetchAndCachePut(e)}catch(t){a=t}return t&&clearTimeout(t),!a&&i||(i=await r.cacheMatch(e)),i}},t.NetworkOnly=class extends w{async q(t,e){let r,a;try{a=await e.fetch(t)}catch(t){r=t}if(!a)throw new s.WorkboxError("no-response",{url:t.url,error:r});return a}},t.StaleWhileRevalidate=class extends w{constructor(t){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f)}async q(t,e){const r=e.fetchAndCachePut(t).catch((()=>{}));let a,i=await e.cacheMatch(t);if(i);else try{i=await r}catch(t){a=t}if(!i)throw new s.WorkboxError("no-response",{url:t.url,error:a});return i}},t.Strategy=w,t.StrategyHandler=u,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
this.workbox=this.workbox||{},this.workbox.strategies=function(t,e,s,r,i,n,a,o,c){"use strict";function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t}).apply(this,arguments)}try{self["workbox:strategies:6.0.0-alpha.3"]&&_()}catch(t){}function l(t){return"string"==typeof t?new Request(t):t}class u{constructor(t,e){this.t={},Object.assign(this,e),this.event=e.event,this.i=t,this.o=new a.Deferred,this.h=[],this.l=[...t.plugins],this.u=new Map;for(const t of this.l)this.u.set(t,{});this.event.waitUntil(this.o.promise)}fetch(t){return this.waitUntil((async()=>{const{event:e}=this;let r=l(t);if("navigate"===r.mode&&e instanceof FetchEvent&&e.preloadResponse){const t=await e.preloadResponse;if(t)return t}const i=this.hasCallback("fetchDidFail")?r.clone():null;try{for(const t of this.iterateCallbacks("requestWillFetch"))r=await t({request:r.clone(),event:e})}catch(t){throw new s.WorkboxError("plugin-error-request-will-fetch",{thrownError:t})}const n=r.clone();try{let t;t=await fetch(r,"navigate"===r.mode?void 0:this.i.fetchOptions);for(const s of this.iterateCallbacks("fetchDidSucceed"))t=await s({event:e,request:n,response:t});return t}catch(t){throw i&&await this.runCallbacks("fetchDidFail",{error:t,event:e,originalRequest:i.clone(),request:n.clone()}),t}})())}async fetchAndCachePut(t){const e=await this.fetch(t),s=e.clone();return this.waitUntil(this.cachePut(t,s)),e}cacheMatch(t){return this.waitUntil((async()=>{const e=l(t);let s;const{cacheName:r,matchOptions:i}=this.i,n=await this.getCacheKey(e,"read"),a=h({},i,{cacheName:r});s=await caches.match(n,a);for(const t of this.iterateCallbacks("cachedResponseWillBeUsed"))s=await t({cacheName:r,matchOptions:i,cachedResponse:s,request:n,event:this.event})||void 0;return s})())}async cachePut(t,e){const r=l(t);await c.timeout(0);const a=await this.getCacheKey(r,"write");if(!e)throw new s.WorkboxError("cache-put-with-no-response",{url:i.getFriendlyURL(a.url)});const h=await this.p(e);if(!h)return;const{cacheName:u,matchOptions:w}=this.i,f=await self.caches.open(u),d=this.hasCallback("cacheDidUpdate"),p=d?await n.cacheMatchIgnoreParams(f,a.clone(),["__WB_REVISION__"],w):null;try{await f.put(a,d?h.clone():h)}catch(t){throw"QuotaExceededError"===t.name&&await o.executeQuotaErrorCallbacks(),t}for(const t of this.iterateCallbacks("cacheDidUpdate"))await t({cacheName:u,oldResponse:p,newResponse:h.clone(),request:a,event:this.event})}async getCacheKey(t,e){if(!this.t[e]){let s=t;for(const t of this.iterateCallbacks("cacheKeyWillBeUsed"))s=l(await t({mode:e,request:s,event:this.event,params:this.params}));this.t[e]=s}return this.t[e]}hasCallback(t){for(const e of this.i.plugins)if(t in e)return!0;return!1}async runCallbacks(t,e){for(const s of this.iterateCallbacks(t))await s(e)}*iterateCallbacks(t){for(const e of this.i.plugins)if("function"==typeof e[t]){const s=this.u.get(e),r=r=>{const i=h({},r,{state:s});return e[t](i)};yield r}}waitUntil(t){return this.h.push(t),t}async doneWaiting(){let t;for(;t=this.h.shift();)await t}destroy(){this.o.resolve()}async p(t){let e=t,s=!1;for(const t of this.iterateCallbacks("cacheWillUpdate"))if(e=await t({request:this.request,response:e,event:this.event})||void 0,s=!0,!e)break;return s||e&&200!==e.status&&(e=void 0),e}}class w{constructor(t={}){this.cacheName=r.cacheNames.getRuntimeName(t.cacheName),this.plugins=t.plugins||[],this.fetchOptions=t.fetchOptions,this.matchOptions=t.matchOptions}handle(t){const[e]=this.handleAll(t);return e}handleAll(t){t instanceof FetchEvent&&(t={event:t,request:t.request});const e=t.event,s="string"==typeof t.request?new Request(t.request):t.request,r="params"in t?t.params:void 0,i=new u(this,{event:e,request:s,params:r}),n=this.v(i,s,e);return[n,this.m(n,i,s,e)]}async v(t,e,r){await t.runCallbacks("handlerWillStart",{event:r,request:e});let i=void 0;try{if(i=await this.q(e,t),!i||"error"===i.type)throw new s.WorkboxError("no-response",{url:e.url})}catch(s){for(const n of t.iterateCallbacks("handlerDidError"))if(i=await n({error:s,event:r,request:e}),i)break;if(!i)throw s}for(const s of t.iterateCallbacks("handlerWillRespond"))i=await s({event:r,request:e,response:i});return i}async m(t,e,s,r){let i,n;try{i=await t}catch(n){}try{await e.runCallbacks("handlerDidRespond",{event:r,request:s,response:i}),await e.doneWaiting()}catch(t){n=t}if(await e.runCallbacks("handlerDidComplete",{event:r,request:s,response:i,error:n}),e.destroy(),n)throw n}}const f={cacheWillUpdate:async({response:t})=>200===t.status||0===t.status?t:null};return t.CacheFirst=class extends w{async q(t,e){let r,i=await e.cacheMatch(t);if(!i)try{i=await e.fetchAndCachePut(t)}catch(t){r=t}if(!i)throw new s.WorkboxError("no-response",{url:t.url,error:r});return i}},t.CacheOnly=class extends w{async q(t,e){const r=await e.cacheMatch(t);if(!r)throw new s.WorkboxError("no-response",{url:t.url});return r}},t.NetworkFirst=class extends w{constructor(t={}){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f),this._=t.networkTimeoutSeconds||0}async q(t,e){const r=[],i=[];let n;if(this._){const{id:s,promise:a}=this.g({request:t,logs:r,handler:e});n=s,i.push(a)}const a=this.k({timeoutId:n,request:t,logs:r,handler:e});i.push(a);for(const t of i)e.waitUntil(t);let o=await Promise.race(i);if(o||(o=await a),!o)throw new s.WorkboxError("no-response",{url:t.url});return o}g({request:t,logs:e,handler:s}){let r;return{promise:new Promise((e=>{r=setTimeout((async()=>{e(await s.cacheMatch(t))}),1e3*this._)})),id:r}}async k({timeoutId:t,request:e,logs:s,handler:r}){let i,n;try{n=await r.fetchAndCachePut(e)}catch(t){i=t}return t&&clearTimeout(t),!i&&n||(n=await r.cacheMatch(e)),n}},t.NetworkOnly=class extends w{constructor(t={}){super(t),this._=t.networkTimeoutSeconds||0}async q(t,e){let r,i=void 0;try{const s=[e.fetch(t)];if(this._){const t=c.timeout(1e3*this._);s.push(t)}if(r=await Promise.race(s),!r)throw new Error("Timed out the network response after "+this._+" seconds.")}catch(t){i=t}if(!r)throw new s.WorkboxError("no-response",{url:t.url,error:i});return r}},t.StaleWhileRevalidate=class extends w{constructor(t){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f)}async q(t,e){const r=e.fetchAndCachePut(t).catch((()=>{}));let i,n=await e.cacheMatch(t);if(n);else try{n=await r}catch(t){i=t}if(!n)throw new s.WorkboxError("no-response",{url:t.url,error:i});return n}},t.Strategy=w,t.StrategyHandler=u,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
//# sourceMappingURL=workbox-strategies.prod.js.map |
@@ -1,4 +0,7 @@ | ||
import { Strategy } from './Strategy.js'; | ||
import { Strategy, StrategyOptions } from './Strategy.js'; | ||
import { StrategyHandler } from './StrategyHandler.js'; | ||
import './_version.js'; | ||
interface NetworkOnlyOptions extends Omit<StrategyOptions, 'cacheName' | 'matchOptions'> { | ||
networkTimeoutSeconds?: number; | ||
} | ||
/** | ||
@@ -18,3 +21,15 @@ * An implementation of a | ||
declare class NetworkOnly extends Strategy { | ||
private readonly _networkTimeoutSeconds; | ||
/** | ||
* @param {Object} [options] | ||
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins} | ||
* to use in conjunction with this caching strategy. | ||
* @param {Object} [options.fetchOptions] Values passed along to the | ||
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) | ||
* of all fetch() requests made by this strategy. | ||
* @param {number} [options.networkTimeoutSeconds] If set, any network requests | ||
* that fail to respond within the timeout will result in a network error. | ||
*/ | ||
constructor(options?: NetworkOnlyOptions); | ||
/** | ||
* @private | ||
@@ -28,2 +43,2 @@ * @param {Request|string} request A request to run this strategy for. | ||
} | ||
export { NetworkOnly }; | ||
export { NetworkOnly, NetworkOnlyOptions }; |
@@ -10,2 +10,3 @@ /* | ||
import { logger } from 'workbox-core/_private/logger.js'; | ||
import { timeout } from 'workbox-core/_private/timeout.js'; | ||
import { WorkboxError } from 'workbox-core/_private/WorkboxError.js'; | ||
@@ -30,2 +31,16 @@ import { Strategy } from './Strategy.js'; | ||
/** | ||
* @param {Object} [options] | ||
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins} | ||
* to use in conjunction with this caching strategy. | ||
* @param {Object} [options.fetchOptions] Values passed along to the | ||
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) | ||
* of all fetch() requests made by this strategy. | ||
* @param {number} [options.networkTimeoutSeconds] If set, any network requests | ||
* that fail to respond within the timeout will result in a network error. | ||
*/ | ||
constructor(options = {}) { | ||
super(options); | ||
this._networkTimeoutSeconds = options.networkTimeoutSeconds || 0; | ||
} | ||
/** | ||
* @private | ||
@@ -42,10 +57,19 @@ * @param {Request|string} request A request to run this strategy for. | ||
className: this.constructor.name, | ||
funcName: 'handle', | ||
funcName: '_handle', | ||
paramName: 'request', | ||
}); | ||
} | ||
let error; | ||
let error = undefined; | ||
let response; | ||
try { | ||
response = await handler.fetch(request); | ||
const promises = [handler.fetch(request)]; | ||
if (this._networkTimeoutSeconds) { | ||
const timeoutPromise = timeout(this._networkTimeoutSeconds * 1000); | ||
promises.push(timeoutPromise); | ||
} | ||
response = await Promise.race(promises); | ||
if (!response) { | ||
throw new Error(`Timed out the network response after ` + | ||
`${this._networkTimeoutSeconds} seconds.`); | ||
} | ||
} | ||
@@ -52,0 +76,0 @@ catch (err) { |
{ | ||
"name": "workbox-strategies", | ||
"version": "6.0.0-alpha.3", | ||
"version": "6.0.0-rc.0", | ||
"license": "MIT", | ||
@@ -26,5 +26,5 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "^6.0.0-alpha.3" | ||
"workbox-core": "^6.0.0-rc.0" | ||
}, | ||
"gitHead": "00ba07467b253751e874f53f424f2adb1c06e176" | ||
"gitHead": "43c375f60c986a23a25a1c04ad83ed94783c39d1" | ||
} |
// @ts-ignore | ||
try{self['workbox:strategies:6.0.0-alpha.2']&&_()}catch(e){} | ||
try{self['workbox:strategies:6.0.0-alpha.3']&&_()}catch(e){} |
@@ -11,5 +11,6 @@ /* | ||
import {logger} from 'workbox-core/_private/logger.js'; | ||
import {timeout} from 'workbox-core/_private/timeout.js'; | ||
import {WorkboxError} from 'workbox-core/_private/WorkboxError.js'; | ||
import {Strategy} from './Strategy.js'; | ||
import {Strategy, StrategyOptions} from './Strategy.js'; | ||
import {StrategyHandler} from './StrategyHandler.js'; | ||
@@ -20,2 +21,6 @@ import {messages} from './utils/messages.js'; | ||
interface NetworkOnlyOptions extends Omit<StrategyOptions, 'cacheName' | 'matchOptions'> { | ||
networkTimeoutSeconds?: number; | ||
} | ||
/** | ||
@@ -35,3 +40,21 @@ * An implementation of a | ||
class NetworkOnly extends Strategy { | ||
private readonly _networkTimeoutSeconds: number; | ||
/** | ||
* @param {Object} [options] | ||
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins} | ||
* to use in conjunction with this caching strategy. | ||
* @param {Object} [options.fetchOptions] Values passed along to the | ||
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) | ||
* of all fetch() requests made by this strategy. | ||
* @param {number} [options.networkTimeoutSeconds] If set, any network requests | ||
* that fail to respond within the timeout will result in a network error. | ||
*/ | ||
constructor(options: NetworkOnlyOptions = {}) { | ||
super(options); | ||
this._networkTimeoutSeconds = options.networkTimeoutSeconds || 0; | ||
} | ||
/** | ||
* @private | ||
@@ -48,3 +71,3 @@ * @param {Request|string} request A request to run this strategy for. | ||
className: this.constructor.name, | ||
funcName: 'handle', | ||
funcName: '_handle', | ||
paramName: 'request', | ||
@@ -54,6 +77,18 @@ }); | ||
let error; | ||
let response; | ||
let error: Error | undefined = undefined; | ||
let response: Response | undefined; | ||
try { | ||
response = await handler.fetch(request); | ||
const promises: Promise<Response|undefined>[] = [handler.fetch(request)]; | ||
if (this._networkTimeoutSeconds) { | ||
const timeoutPromise = timeout(this._networkTimeoutSeconds * 1000) as Promise<undefined>; | ||
promises.push(timeoutPromise); | ||
} | ||
response = await Promise.race(promises); | ||
if (!response) { | ||
throw new Error(`Timed out the network response after ` + | ||
`${this._networkTimeoutSeconds} seconds.`); | ||
} | ||
} catch (err) { | ||
@@ -82,2 +117,2 @@ error = err; | ||
export {NetworkOnly}; | ||
export {NetworkOnly, NetworkOnlyOptions}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
412499
4600
Updatedworkbox-core@^6.0.0-rc.0