const fileName_1 = "(@effect/core) _src/io/Schedule/operations/fromDurations.ts";
import * as tsplus_module_1 from "@tsplus/stdlib/collections/Chunk/definition";
import * as tsplus_module_2 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/unsafeGet";
import * as tsplus_module_4 from "@effect/core/io/Schedule/Interval";
import * as tsplus_module_5 from "@tsplus/stdlib/collections/Chunk/drop";
import * as tsplus_module_6 from "@effect/core/io/Schedule/Decision";
import * as tsplus_module_7 from "@tsplus/stdlib/collections/Chunk/prepend";
import * as tsplus_module_8 from "@tsplus/stdlib/data/Duration";
import * as tsplus_module_9 from "@effect/core/io/Effect/operations/succeed";
import { makeWithState } from "@effect/core/io/Schedule/operations/_internal/makeWithState";
/**
 * 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
 */

export function fromDurations(duration, ...durations) {
  return 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.mjs.map