UNPKG

@embrace-io/web-sdk

Version:
3 lines (2 loc) 1.18 kB
import{__awaiter as t,__generator as r}from"tslib";import"uuid";import{OTelPerformanceManager as n}from"../../utils/PerformanceManager/OTelPerformanceManager.js";import{MAX_ATTEMPTS as e,MAX_BACKOFF as o,BACKOFF_MULTIPLIER as i,INITIAL_BACKOFF as s,JITTER as a}from"./constants.js";var u=function(){function u(t,r){void 0===r&&(r=new n),this._transport=t,this._perf=r}return u.prototype.send=function(n,u){return t(this,void 0,void 0,(function(){var t,c,p,f,h,l,m,d;return r(this,(function(r){switch(r.label){case 0:return t=this._perf.getNowMillis()+u,[4,this._transport.send(n,u)];case 1:c=r.sent(),p=e,f=s,r.label=2;case 2:return"retryable"===c.status&&p>0?(p--,h=Math.max(Math.min(f,o)+(Math.random()*(2*a)-a),0),f*=i,l=null!==(d=c.retryInMillis)&&void 0!==d?d:h,m=t-this._perf.getNowMillis(),l>m?[2,c]:[4,this._retry(n,m,l)]):[3,4];case 3:return c=r.sent(),[3,2];case 4:return[2,c]}}))}))},u.prototype.shutdown=function(){this._transport.shutdown()},u.prototype._retry=function(t,r,n){var e=this;return new Promise((function(o,i){setTimeout((function(){e._transport.send(t,r).then(o,i)}),n)}))},u}();export{u as RetryingTransport}; //# sourceMappingURL=RetryingTransport.js.map