MCPcopy Create free account
hub / github.com/Effect-TS/effect / fromIteratorEagerUnsafe

Function fromIteratorEagerUnsafe

packages/effect/src/internal/effect.ts:1538–1576  ·  view source on GitHub ↗
(
  evaluate: () => Iterator<Effect.Effect<any, any, any>>
)

Source from the content-addressed store, hash-verified

1536}
1537
1538const fromIteratorEagerUnsafe = (
1539 evaluate: () => Iterator<Effect.Effect<any, any, any>>
1540): Effect.Effect<any, any, any> => {
1541 try {
1542 const iterator = evaluate()
1543 let value: any = undefined
1544
1545 // Try to resolve synchronously in a loop
1546 while (true) {
1547 const state = iterator.next(value)
1548
1549 if (state.done) {
1550 return succeed(state.value)
1551 }
1552
1553 const primitive = state.value as any
1554
1555 if (primitive && primitive._tag === "Success") {
1556 value = primitive.value
1557 continue
1558 } else if (primitive && primitive._tag === "Failure") {
1559 return state.value
1560 } else {
1561 let isFirstExecution = true
1562
1563 return suspend(() => {
1564 if (isFirstExecution) {
1565 isFirstExecution = false
1566 return flatMap(state.value, (value) => fromIteratorUnsafe(iterator, value))
1567 } else {
1568 return suspend(() => fromIteratorUnsafe(evaluate()))
1569 }
1570 })
1571 }
1572 }
1573 } catch (error) {
1574 return die(error)
1575 }
1576}
1577
1578const fromIteratorUnsafe: (
1579 iterator: Iterator<Effect.Effect<any, any, any>>,

Callers 1

fnUntracedEagerFunction · 0.85

Calls 6

evaluateFunction · 0.90
flatMapFunction · 0.85
succeedFunction · 0.70
dieFunction · 0.70
nextMethod · 0.65
suspendFunction · 0.50

Tested by

no test coverage detected