UNPKG

@embrace-io/web-sdk

Version:
3 lines (2 loc) 852 B
import"uuid";import{OTelPerformanceManager as t}from"../../utils/PerformanceManager/OTelPerformanceManager.js";import{MAX_ATTEMPTS as r,INITIAL_BACKOFF as s,MAX_BACKOFF as e,BACKOFF_MULTIPLIER as n,JITTER as o}from"./constants.js";class i{constructor(r,s=new t){this._transport=r,this._perf=s}async send(t,i){var a;const h=this._perf.getNowMillis()+i;let l=await this._transport.send(t,i),m=r,u=s;for(;"retryable"===l.status&&m>0;){m--;const r=Math.max(Math.min(u,e)+(Math.random()*(2*o)-o),0);u*=n;const s=null!==(a=l.retryInMillis)&&void 0!==a?a:r,i=h-this._perf.getNowMillis();if(s>i)return l;l=await this._retry(t,i,s)}return l}shutdown(){this._transport.shutdown()}_retry(t,r,s){return new Promise(((e,n)=>{setTimeout((()=>{this._transport.send(t,r).then(e,n)}),s)}))}}export{i as RetryingTransport}; //# sourceMappingURL=RetryingTransport.js.map