src/util/retry.js
function retry(fn) {

  return function retried() {

    var args = arguments.length ? Array.prototype.slice.call(arguments, 0, arguments.length - 1) : [];
    var done = arguments.length ? arguments[arguments.length - 1] : noop;

    var cfn = null;
    var canceled = false;

    function exec() {
      var err = arguments[0];
      if (!err || canceled) {
        done.apply(null, arguments);
      } else {
        cfn = fn.apply(null, args);
      }
    }

    args.push(exec);
    exec(true);

    return function cancel() {
      canceled = true;
      cfn.apply(null, arguments);
    };

  };

}
function retry(fn) {

  return function retried() {

    var args = arguments.length ? Array.prototype.slice.call(arguments, 0, arguments.length - 1) : [];
    var done = arguments.length ? arguments[arguments.length - 1] : noop;

    var cfn = null;
    var canceled = false;

    function exec() {
      var err = arguments[0];
      if (!err || canceled) {
        done.apply(null, arguments);
      } else {
        cfn = fn.apply(null, args);
      }
    }

    args.push(exec);
    exec(true);

    return function cancel() {
      canceled = true;
      cfn.apply(null, arguments);
    };

  };

}
function retry ( fn ) { return function retried ( ) { var args = arguments . length ? Array . prototype . slice . call ( arguments , 0 , arguments . length - 1 ) : [ ] ; var done = arguments . length ? arguments [ arguments . length - 1 ] : noop ; var cfn = null ; var canceled = false ; function exec ( ) { var err = arguments [ 0 ] ; if ( ! err || canceled ) { done . apply ( null , arguments ) ; } else { cfn = fn . apply ( null , args ) ; } } args . push ( exec ) ; exec ( true ) ; return function cancel ( ) { canceled = true ; cfn . apply ( null , arguments ) ; } ; } ; }
Return a cancelable function that executes fn in a loop until it returns successfully.
Return a cancelable function that executes fn in a loop until it returns successfully .