/** * Runs a schedule using the provided inputs, and collects all outputs. * * @tsplus static effect/core/io/Schedule.Aspects run * @tsplus pipeable effect/core/io/Schedule run */ export function run(now: number, input: Collection) { return (self: Schedule): Effect> => runLoop(self, now, List.from(input), self.initial, Chunk.empty()) } function runLoop( self: Schedule, now: number, inputs: List, state: State, acc: Chunk ): Effect> { if (inputs.isNil()) { return Effect.succeed(acc) } const input = inputs.head const nextInputs = inputs.tail return self .step(now, input, state) .flatMap(([state, out, decision]) => { switch (decision._tag) { case "Done": { return Effect.sync(acc.append(out)) } case "Continue": { return runLoop( self, decision.intervals.start, nextInputs, state, acc.append(out) ) } } }) }