"use strict";

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

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/definition"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Tuple/make"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/unsafeGet"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Schedule/Interval"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/drop"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Schedule/Decision"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/prepend"));

var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Duration"));

var tsplus_module_9 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/succeed"));

var _makeWithState = /*#__PURE__*/require("@effect/core/io/Schedule/operations/_internal/makeWithState");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const fileName_1 = "(@effect/core) _src/io/Schedule/operations/fromDurations.ts";

/**
 * A schedule that recurs once for each of the specified durations, delaying
 * each time for the length of the specified duration. Returns the length of
 * the current duration between recurrences.
 *
 * @tsplus static ets/Schedule/Ops fromDurations
 */
function fromDurations(duration, ...durations) {
  return (0, _makeWithState.makeWithState)(tsplus_module_2.make(tsplus_module_1.from([duration, ...durations]), true), (now, _, {
    tuple: [durations, cont]
  }) => tsplus_module_9.succeed(() => {
    if (cont) {
      const x = tsplus_module_3.unsafeGet_(durations, 0);
      const interval = tsplus_module_4.after(now + x.millis);

      if (durations.length >= 2) {
        return tsplus_module_2.make(tsplus_module_2.make(tsplus_module_5.drop_(durations, 1), true), x, tsplus_module_6._continue(interval));
      }

      const y = tsplus_module_5.drop_(durations, 1);
      return tsplus_module_2.make(tsplus_module_2.make(tsplus_module_7.prepend_(y, x), false), x, tsplus_module_6._continue(interval));
    }

    return tsplus_module_2.make(tsplus_module_2.make(durations, false), tsplus_module_8.millis(0), tsplus_module_6.done);
  }, fileName_1 + ":24:21"));
}
//# sourceMappingURL=fromDurations.js.map