UNPKG

node-red-contrib-home-assistant-websocket

Version:
2 lines (1 loc) 1.11 kB
"use strict";var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var E=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},d=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of l(e))!y.call(r,a)&&a!==t&&s(r,a,{get:()=>e[a],enumerable:!(n=f(e,a))||n.enumerable});return r};var R=r=>d(s({},"__esModule",{value:!0}),r);var h={};E(h,{isDefaultRetriable:()=>c,retryWithBackoff:()=>M});module.exports=R(h);function c(r){const e=r?.code;if(e==="ECONNREFUSED"||e==="ETIMEDOUT"||e==="ECONNRESET"||e==="ENETUNREACH"||e==="EAI_AGAIN")return!0;const t=r?.response?.status;return!!(t&&[429,500,502,503,504].includes(t))}async function M(r,e){const t=e.factor??2;let n=0,a=e.baseMs;for(;;)try{return await r()}catch(i){const u=e.isRetriable?e.isRetriable(i):c(i),b=n>=e.retries;if(!u||b){try{e.onGiveUp?.(i)}catch{}throw i}const o=Math.min(a,e.maxMs);try{e.beforeRetry?.(n,o,i)}catch{}await new Promise(m=>setTimeout(m,o)),a=Math.min(a*t,e.maxMs),n+=1}}0&&(module.exports={isDefaultRetriable,retryWithBackoff});