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

Function fromIteratorEagerUnsafe

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

Source from the content-addressed store, hash-verified

1313 )
1314
1315const 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
1355const fromIteratorUnsafe: (
1356 iterator: Iterator<Effect.Effect<any, any, any>>,

Callers 1

fnUntracedEagerFunction · 0.85

Calls 5

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

Tested by

no test coverage detected