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

Method runLoop

packages/effect/src/internal/effect.ts:628–678  ·  view source on GitHub ↗
(effect: Primitive)

Source from the content-addressed store, hash-verified

626 this.context = Context.empty()
627 }
628 runLoop(effect: Primitive): Exit.Exit<A, E> | Yield {
629 const prevFiber = (globalThis as any)[currentFiberTypeId]
630 ;(globalThis as any)[currentFiberTypeId] = this
631 const prevRunning = this._running
632 this._running = true
633 let yielding = false
634 let current: Primitive | Yield = effect
635 this.currentOpCount = 0
636 try {
637 while (true) {
638 if (this._deferredInterrupt) {
639 this._deferredInterrupt = false
640 current = failCause(this._interruptedCause!) as any
641 }
642 this.currentOpCount++
643 if (
644 !yielding &&
645 !this.currentPreventYield &&
646 this.currentScheduler.shouldYield(this as any)
647 ) {
648 yielding = true
649 const prev = current
650 current = flatMap(yieldNow, () => prev as any) as any
651 }
652 current = this.currentTracerContext
653 ? this.currentTracerContext(current as any, this)
654 : (current as any)[evaluate](this)
655 if (current === Yield) {
656 const yielded = this._yielded!
657 if (ExitTypeId in yielded) {
658 this._deferredInterrupt = false
659 this._yielded = undefined
660 return yielded
661 } else if (this._deferredInterrupt) {
662 this._yielded = undefined
663 yielded()
664 continue
665 }
666 return Yield
667 }
668 }
669 } catch (error) {
670 if (!hasProperty(current, evaluate)) {
671 return exitDie(`Fiber.runLoop: Not a valid effect: ${String(current)}`)
672 }
673 return this.runLoop(exitDie(error) as any)
674 } finally {
675 this._running = prevRunning
676 ;(globalThis as any)[currentFiberTypeId] = prevFiber
677 }
678 }
679 getCont<S extends contA | contE>(symbol: S):
680 | (Primitive & Record<S, (value: any, fiber: FiberImpl) => Primitive>)
681 | undefined

Callers 1

evaluateMethod · 0.95

Calls 4

exitDieFunction · 0.90
shouldYieldMethod · 0.65
failCauseFunction · 0.50
StringInterface · 0.50

Tested by

no test coverage detected