UNPKG

callforth

Version:

A tiny utility library to conveniently replace callbacks with Promises.

3 lines (2 loc) 894 B
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).callforth={})}(this,function(e){var n=function(e){return new Promise(function(n){return setTimeout(n,e)})};e.eventOn=function(e,n,t){var r,o;void 0===t&&(t="error");var i=new Promise(function(e,n){r=e,o=n});return e.addEventListener(n,r),e.addEventListener(t,o),i.finally(function(){e.removeEventListener(n,r),e.removeEventListener(t,o)}),i},e.polling=function e(t,r){void 0===r&&(r={});try{var o=r.maxTries,i=void 0===o?10:o,f=r.interval,u=void 0===f?10:f;return Promise.resolve(function(){if(i<=0)throw void 0;return t()?void 0:Promise.resolve(n(u)).then(function(){return Promise.resolve(e(t,{maxTries:i-1,interval:u})).then(function(){})})}())}catch(e){return Promise.reject(e)}},e.timeout=n}); //# sourceMappingURL=callforth.umd.js.map