"use strict";

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

var _promise = require("babel-runtime/core-js/promise");

var _promise2 = _interopRequireDefault(_promise);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Chain promises so that they are evaluated in order.
 * @returns {object} - The promise queue object.
 */
var PromiseQueue = function PromiseQueue() {
  var promise = _promise2.default.resolve();

  return {
    push: function push(fn) {
      promise = promise.then(fn, fn);
    },
    fetch: function fetch(fn) {
      var returnResolver = void 0;
      var returnRejecter = void 0;
      var returnPromise = new _promise2.default(function (resolve, reject) {
        returnResolver = resolve;
        returnRejecter = reject;
      });
      promise = promise.then(fn, fn).then(function (res) {
        return returnResolver(res);
      }, function (err) {
        return returnRejecter(err);
      });

      return returnPromise;
    }
  };
};

exports.default = PromiseQueue;
//# sourceMappingURL=PromiseQueue.js.map