| 1313 | ) |
| 1314 | |
| 1315 | const fromIteratorEagerUnsafe = ( |
| 1316 | evaluate: () => Iterator<Effect.Effect<any, any, any>> |
| 1317 | ): Effect.Effect<any, any, any> => { |
| 1318 | try { |
| 1319 | const iterator = evaluate() |
| 1320 | let value: any = undefined |
| 1321 | |
| 1322 | // Try to resolve synchronously in a loop |
| 1323 | while (true) { |
| 1324 | const state = iterator.next(value) |
| 1325 | |
| 1326 | if (state.done) { |
| 1327 | return succeed(state.value) |
| 1328 | } |
| 1329 | |
| 1330 | const primitive = state.value as any |
| 1331 | |
| 1332 | if (primitive && primitive._tag === "Success") { |
| 1333 | value = primitive.value |
| 1334 | continue |
| 1335 | } else if (primitive && primitive._tag === "Failure") { |
| 1336 | return state.value |
| 1337 | } else { |
| 1338 | let isFirstExecution = true |
| 1339 | |
| 1340 | return suspend(() => { |
| 1341 | if (isFirstExecution) { |
| 1342 | isFirstExecution = false |
| 1343 | return flatMap(state.value, (value) => fromIteratorUnsafe(iterator, value)) |
| 1344 | } else { |
| 1345 | return suspend(() => fromIteratorUnsafe(evaluate())) |
| 1346 | } |
| 1347 | }) |
| 1348 | } |
| 1349 | } |
| 1350 | } catch (error) { |
| 1351 | return die(error) |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | const fromIteratorUnsafe: ( |
| 1356 | iterator: Iterator<Effect.Effect<any, any, any>>, |