Skip to content

Instantly share code, notes, and snippets.

@eclipseo
Created August 20, 2022 19:41
Show Gist options
  • Save eclipseo/b8f55f82c460e454d5d434c220ad22e2 to your computer and use it in GitHub Desktop.
Save eclipseo/b8f55f82c460e454d5d434c220ad22e2 to your computer and use it in GitHub Desktop.
!function(e){"use strict";function n(e){e=e||{};var n,o,r,i=0,c=e.backoff||1,a=e.interval,l=e.timeout||15e3,u={cancel:function(){e.debug&&console.log("harness.cancel"),r?(clearTimeout(r),o.reject(t.CancellationError())):n&&(n.cancel(),o.reject(t.CancellationError()))},go:function(u){if(e.debug&&console.log("harness.go"),o=t.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?u.apply(u,s):u(),n.timeout(l).then(o.resolve.bind(o))["catch"](t.CancellationError,function(e){o.reject(e)})["catch"](function(t){if(e.attempt&&i>=e.attempt)return void o.reject(t);var l=a&&i>1?a+(i-1)*c:0;e.debug&&console.log(" ",t,"retry in:",l+"ms"),n=void 0,r=setTimeout(function(){r=void 0,d()},l)})};return d(),o.promise}};return u}var o,t;null!=e&&(o=e.harness),"undefined"!=typeof module&&module.exports?(t=require("bluebird"),module.exports=n):"undefined"!=typeof define&&define.amd?(t=e.Promise,define([],function(){return n})):(t=e.Promise,e.harness=n),t.config({cancellation:!0}),n.noConflict=function(){return e.harness=o,n}}(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment