| 1536 | } |
| 1537 | |
| 1538 | const 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 | |
| 1578 | const fromIteratorUnsafe: ( |
| 1579 | iterator: Iterator<Effect.Effect<any, any, any>>, |