()
| 4767 | } |
| 4768 | |
| 4769 | const go = (): Effect.Effect<void, E | E2, R> | undefined => { |
| 4770 | let paused = false |
| 4771 | for (; !terminal && index < end; index++) { |
| 4772 | const item = items[index] |
| 4773 | const eff = effect ?? onItem(state, item, index) |
| 4774 | |
| 4775 | // fast case (already an exit) |
| 4776 | if (effectIsExit(eff)) { |
| 4777 | terminal = runStep(item, eff, index) |
| 4778 | if (terminal) break |
| 4779 | |
| 4780 | // We have an effect, so enter "async" mode |
| 4781 | } else if (!parentFiber) { |
| 4782 | return callback((cb) => { |
| 4783 | parentFiber = getCurrentFiber()! |
| 4784 | fibers = new Set() |
| 4785 | effect = eff |
| 4786 | resume = cb |
| 4787 | let result: Effect.Effect<void, E | E2, R> | undefined |
| 4788 | try { |
| 4789 | result = go() |
| 4790 | } catch (error) { |
| 4791 | return cb(failDefect(error)) |
| 4792 | } |
| 4793 | if (result) return cb(result) |
| 4794 | return suspend(() => { |
| 4795 | terminal = exitVoid |
| 4796 | interrupted = true |
| 4797 | return fibers ? fiberInterruptAll(fibers) : void_ |
| 4798 | }) |
| 4799 | }) |
| 4800 | |
| 4801 | // Fork the effect with concurrency > 1 |
| 4802 | } else { |
| 4803 | // Clear the temporary effect from capturing the parentFiber |
| 4804 | effect = undefined |
| 4805 | |
| 4806 | const fiber = forkUnsafe(parentFiber, eff, true, true, "inherit") |
| 4807 | if (fiber._exit) { |
| 4808 | terminal = runStep(item, fiber._exit, index) |
| 4809 | if (terminal) break |
| 4810 | continue |
| 4811 | } |
| 4812 | |
| 4813 | // Add the fiber to the Set |
| 4814 | fibers!.add(fiber) |
| 4815 | |
| 4816 | const currentIndex = index |
| 4817 | fiber.addObserver((exit) => { |
| 4818 | fibers!.delete(fiber) |
| 4819 | try { |
| 4820 | if (terminal) { |
| 4821 | if (!interrupted && exit._tag === "Failure") { |
| 4822 | for (const reason of exit.cause.reasons) { |
| 4823 | if (reason._tag === "Interrupt") continue |
| 4824 | else if (terminal._tag === "Failure") { |
| 4825 | ;(terminal.cause.reasons as Array<any>).push(reason) |
| 4826 | } else { |
no test coverage detected