define(["exports", "core/post-process", "core/pre-process", "core/pubsubhub", "core/default-root-attr", "core/include-config", "core/override-configuration", "core/remove-respec", "core/respec-ready", "deps/regenerator"], function (exports, _postProcess, _preProcess, _pubsubhub) {
  "use strict";

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.runAll = undefined;

  function _asyncToGenerator(fn) {
    return function () {
      var gen = fn.apply(this, arguments);
      return new Promise(function (resolve, reject) {
        function step(key, arg) {
          try {
            var info = gen[key](arg);
            var value = info.value;
          } catch (error) {
            reject(error);
            return;
          }

          if (info.done) {
            resolve(value);
          } else {
            return Promise.resolve(value).then(function (value) {
              step("next", value);
            }, function (err) {
              step("throw", err);
            });
          }
        }

        return step("next");
      });
    };
  }

  function toRunnable(plug) {
    return function (config) {
      return new Promise(function (resolve, reject) {
        plug.run(config, document, resolve);
        setTimeout(function () {
          reject(new Error("Plugin took too long."));
        }, 5000);
      });
    };
  }

  var runAll = exports.runAll = function () {
    var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(plugs) {
      var _this = this;

      var runnables, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, task;

      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              (0, _pubsubhub.pub)("start-all", respecConfig);
              _context.next = 3;
              return _preProcess.done;

            case 3:
              runnables = plugs.filter(function (plug) {
                return plug && typeof plug.run === "function" && plug !== _this;
              }).map(toRunnable);
              _iteratorNormalCompletion = true;
              _didIteratorError = false;
              _iteratorError = undefined;
              _context.prev = 7;
              _iterator = runnables[Symbol.iterator]();

            case 9:
              if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
                _context.next = 22;
                break;
              }

              task = _step.value;
              _context.prev = 11;
              _context.next = 14;
              return task(respecConfig);

            case 14:
              _context.next = 19;
              break;

            case 16:
              _context.prev = 16;
              _context.t0 = _context["catch"](11);

              console.error(_context.t0);

            case 19:
              _iteratorNormalCompletion = true;
              _context.next = 9;
              break;

            case 22:
              _context.next = 28;
              break;

            case 24:
              _context.prev = 24;
              _context.t1 = _context["catch"](7);
              _didIteratorError = true;
              _iteratorError = _context.t1;

            case 28:
              _context.prev = 28;
              _context.prev = 29;

              if (!_iteratorNormalCompletion && _iterator.return) {
                _iterator.return();
              }

            case 31:
              _context.prev = 31;

              if (!_didIteratorError) {
                _context.next = 34;
                break;
              }

              throw _iteratorError;

            case 34:
              return _context.finish(31);

            case 35:
              return _context.finish(28);

            case 36:
              (0, _pubsubhub.pub)("plugins-done", respecConfig);
              _context.next = 39;
              return _postProcess.done;

            case 39:
              (0, _pubsubhub.pub)("end-all", respecConfig);

            case 40:
            case "end":
              return _context.stop();
          }
        }
      }, _callee, this, [[7, 24, 28, 36], [11, 16], [29,, 31, 35]]);
    }));

    return function runAll(_x) {
      return _ref.apply(this, arguments);
    };
  }();
});
//# sourceMappingURL=base-runner.js.map