"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = retry;

var _utils = require("./_utils");

function retry(num, task, callback) {
  var i = 0;

  var _times2 = (0, _utils._times)(num, {
    times: 2
  }),
      times = _times2.times,
      lag = _times2.lag,
      fn = _times2.fn;

  run();

  function cb(err, res) {
    if (!err || i >= times) {
      callback && callback(err, res);
    } else {
      fn(function () {
        run();
      }, lag);
    }
  }

  function run() {
    task(cb, i++);
  }
}