UNPKG

tiny-retry

Version:

Lightweight function to retry an async job until the job success or stop after a maximum number of tries

1 lines 894 B
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["tiny-retry"]=e():t["tiny-retry"]=e()}(this,(function(){return t={868:(t,e,o)=>{const r=o(572);t.exports=async function(t,e){const{maxTries:o=10,delay:n=1e3,startAfter:s=0,process:i,errorHandler:c,check:a}=e;return new Promise((async e=>{await r(s);let f=0;await async function s(){try{f+=1,"function"==typeof i&&i(f);const o=await t();if("function"==typeof a&&!a(o))throw new Error("Unexpected data");e({success:!0,tries:f,data:o})}catch(t){"function"==typeof c&&c(t),f>=o?e({success:!1,tries:f}):(await r(n),await s())}}()}))}},572:t=>{t.exports=t=>new Promise((e=>setTimeout(e,t)))}},e={},function o(r){var n=e[r];if(void 0!==n)return n.exports;var s=e[r]={exports:{}};return t[r](s,s.exports,o),s.exports}(868);var t,e}));