-
Notifications
You must be signed in to change notification settings - Fork 1
/
bluebird-harness.min.js
1 lines (1 loc) · 1.05 KB
/
bluebird-harness.min.js
1
!function(e){"use strict";function n(e){e=e||{};var n,t,r,i=0,c=e.backoff||1,a=e.interval,u=e.timeout||15e3,l={cancel:function(){e.debug&&console.log("harness.cancel"),r?(clearTimeout(r),t.reject(o.CancellationError())):n&&n.cancel()},go:function(l){if(e.debug&&console.log("harness.go"),t=o.pending(),arguments.length>1)var s=Array.prototype.slice.call(arguments,1),f=!0;var d=function(){i++,e.debug&&console.log(" harness.attempt:",i),n=f?l.apply(l,s):l(),n.cancellable().timeout(u).then(t.resolve.bind(t))["catch"](o.CancellationError,function(e){t.reject(e)})["catch"](function(o){if(e.attempt&&i>=e.attempt)return void t.reject(o);var u=a&&i>1?a+(i-1)*c:0;e.debug&&console.log(" ",o,"retry in:",u+"ms"),n=void 0,r=setTimeout(function(){r=void 0,d()},u)})};return d(),t.promise}};return l}var t,o;null!=e&&(t=e.harness),"undefined"!=typeof module&&module.exports?(o=require("bluebird"),module.exports=n):"undefined"!=typeof define&&define.amd?(o=e.Promise,define([],function(){return n})):(o=e.Promise,e.harness=n),n.noConflict=function(){return e.harness=t,n}}(this);