"use strict";

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

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

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

  var _times2 = (0, _utils._times)(num),
      times = _times2.times,
      lag = _times2.lag,
      fn = _times2.fn;

  if (times) {
    run();
  } else {
    callback && callback();
  }

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

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