MCPcopy Index your code
hub / github.com/Effect-TS/effect / runLoop

Method runLoop

packages/effect/src/internal/fiberRuntime.ts:1361–1432  ·  view source on GitHub ↗

* The main run-loop for evaluating effects. * * **NOTE**: This method must be invoked by the fiber itself.

(effect0: Effect.Effect<any, any, any>)

Source from the content-addressed store, hash-verified

1359 * **NOTE**: This method must be invoked by the fiber itself.
1360 */
1361 runLoop(effect0: Effect.Effect<any, any, any>): Exit.Exit<any, any> | YieldedOp {
1362 let cur: Effect.Effect<any, any, any> | YieldedOp = effect0
1363 this.currentOpCount = 0
1364
1365 while (true) {
1366 if ((this.currentRuntimeFlags & OpSupervision) !== 0) {
1367 this.currentSupervisor.onEffect(this, cur)
1368 }
1369 if (this._queue.length > 0) {
1370 cur = this.drainQueueWhileRunning(this.currentRuntimeFlags, cur)
1371 }
1372 if (!this._isYielding) {
1373 this.currentOpCount += 1
1374 const shouldYield = this.currentScheduler.shouldYield(this)
1375 if (shouldYield !== false) {
1376 this._isYielding = true
1377 this.currentOpCount = 0
1378 const oldCur = cur
1379 cur = core.flatMap(core.yieldNow({ priority: shouldYield }), () => oldCur)
1380 }
1381 }
1382 try {
1383 // @ts-expect-error
1384 cur = this.currentTracer.context(
1385 () => {
1386 if (_version !== (cur as core.Primitive)[core.EffectTypeId]._V) {
1387 const level = this.getFiberRef(core.currentVersionMismatchErrorLogLevel)
1388 if (level._tag === "Some") {
1389 const effectVersion = (cur as core.Primitive)[core.EffectTypeId]._V
1390 this.log(
1391 `Executing an Effect versioned ${effectVersion} with a Runtime of version ${version.getCurrentVersion()}, you may want to dedupe the effect dependencies, you can use the language service plugin to detect this at compile time: https://github.com/Effect-TS/language-service`,
1392 internalCause.empty,
1393 level
1394 )
1395 }
1396 }
1397 // @ts-expect-error
1398 return this[(cur as core.Primitive)._op](cur as core.Primitive)
1399 },
1400 this
1401 )
1402
1403 if (cur === YieldedOp) {
1404 const op = yieldedOpChannel.currentOp!
1405 if (
1406 op._op === OpCodes.OP_YIELD ||
1407 op._op === OpCodes.OP_ASYNC
1408 ) {
1409 return YieldedOp
1410 }
1411
1412 yieldedOpChannel.currentOp = null
1413 return (
1414 op._op === OpCodes.OP_SUCCESS ||
1415 op._op === OpCodes.OP_FAILURE
1416 ) ?
1417 op as unknown as Exit.Exit<A, E> :
1418 core.exitFailCause(internalCause.die(op))

Callers 1

evaluateEffectMethod · 0.95

Calls 9

getFiberRefMethod · 0.95
logMethod · 0.95
onEffectMethod · 0.65
shouldYieldMethod · 0.65
contextMethod · 0.65
dieMethod · 0.65
dieMessageMethod · 0.65
interruptMethod · 0.45

Tested by

no test coverage detected