UNPKG

callforth

Version:

A tiny utility library to conveniently replace callbacks with Promises.

3 lines (2 loc) 723 B
var e=function(e,r,n){var t,i;void 0===n&&(n="error");var o=new Promise(function(e,r){t=e,i=r});return e.addEventListener(r,t),e.addEventListener(n,i),o.finally(function(){e.removeEventListener(r,t),e.removeEventListener(n,i)}),o},r=function(e){return new Promise(function(r){return setTimeout(r,e)})},n=function e(n,t){void 0===t&&(t={});try{var i=t.maxTries,o=void 0===i?10:i,v=t.interval,u=void 0===v?10:v;return Promise.resolve(function(){if(o<=0)throw void 0;return n()?void 0:Promise.resolve(r(u)).then(function(){return Promise.resolve(e(n,{maxTries:o-1,interval:u})).then(function(){})})}())}catch(e){return Promise.reject(e)}};export{e as eventOn,n as polling,r as timeout}; //# sourceMappingURL=callforth.mjs.map