UNPKG

1.5 kBJavaScriptView Raw
1"use strict";async function t(t=0){return new Promise(i=>{("number"==typeof t?+t:0)<1?i():setTimeout(i,t)})}Object.defineProperty(exports,"t",{value:!0});class PollingMeasure{constructor(t,i,s){this.name=t,this.duration=i,this.startTime=s,this.entryType="polling-measure"}toJSON(){return{duration:this.duration,entryType:this.entryType,name:this.name,startTime:this.startTime}}}function i(t){return"function"==typeof t.then}class PollingObserver{constructor(t){if(this.conditionCallback=t,this.i=!1,this.s=[],this.o=!1,"function"!=typeof t)throw new TypeError("'conditionCallback' is not defined")}disconnect(){this.i=!0,this.o||(this.s=[])}async observe(s,e){this.i=!1;const{interval:n,timeout:o}=e||{},r="number"==typeof n&&n>0,h="number"==typeof o?+o:-1,a=r?+n:-1,c=await async function(){return("undefined"!=typeof window?window:global).performance}(),u=h<1,f=this.s,l=this.onfinish,y=this.conditionCallback;let p=0,d=void 0,w=0,m="finish",b={};try{t:for(;!this.i;){this.o=!0;const e=y(d,f,this),n=i(e)?await e:e,o=!u&&p>=h;if(o||n){m=o?"timeout":m;break t}const l=c.now(),b=s();d=i(b)?await b:b;const v=c.now()-l,T=r?a-v:0;f.push(new PollingMeasure(`polling:${w}`,v,l)),p+=v>a?v:a,w+=1,T>0&&await t(T)}b={status:m,value:d}}catch(v){b={status:"error",reason:v}}finally{const t=f.slice();this.i&&(this.s=[]),this.o=this.i=!1,"function"==typeof l&&l(b,t,this)}}takeRecords(){return this.s}}exports.PollingObserver=PollingObserver,exports.default=PollingObserver;
2//# sourceMappingURL=index.min.js.map