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

Method evaluate

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

Source from the content-addressed store, hash-verified

636 return this._exit
637 }
638 evaluate(effect: Primitive): void {
639 if (this._exit) {
640 return
641 } else if (this._asyncContext !== undefined) {
642 const asyncContext = this._asyncContext
643 this._asyncContext = undefined
644 let entered = false
645 try {
646 return asyncContext.runInAsyncScope(() => {
647 entered = true
648 return this.evaluate(effect)
649 })
650 } catch (error) {
651 if (entered) throw error
652 // Runtimes like Cloudflare Workers refuse to enter a context captured
653 // during a request that has ended, so resume without it.
654 } finally {
655 // Each captured context is resumed once, so release it for async_hooks
656 // consumers like vitest's detectAsyncLeaks.
657 asyncContext.emitDestroy()
658 }
659 return this.evaluate(effect)
660 } else if (this._yielded !== undefined) {
661 const yielded = this._yielded as () => void
662 this._yielded = undefined
663 yielded()
664 }
665 const exit = this.runLoop(effect)
666 if (exit === Yield) {
667 this._asyncContext = captureAsyncContext()
668 return
669 }
670 // the interruptChildren middleware is added in Effect.forkChild, so it can be
671 // tree-shaken if not used
672 const interruptChildren = fiberMiddleware.interruptChildren &&
673 fiberMiddleware.interruptChildren(this, exit)
674 if (interruptChildren !== undefined) {
675 // uninterruptible, so a pending interrupt cannot replace the exit during the wait
676 this.interruptible = false
677 return this.evaluate(interruptChildren as any)
678 }
679
680 this._exit = exit
681 this.cache.runtimeMetrics?.recordFiberEnd(this.context, exit)
682 if (this._parent) {
683 this._parent._children?.delete(this)
684 this._parent = undefined
685 }
686 this.supervisor?.onEnd(this, exit)
687 if (this._observers !== undefined) {
688 const observers = this._observers
689 this._observers = undefined
690 for (let i = 0; i < observers.length; i++) {
691 observers[i](exit)
692 }
693 }
694 // The stack is already empty: a fiber exits only once its continuations are
695 // popped, or after the run loop clears them for an invalid effect.

Callers 4

interruptUnsafeMethod · 0.95
yieldNowMethod · 0.95
raceAllFunction · 0.95
raceAllFirstFunction · 0.95

Calls 6

runLoopMethod · 0.95
captureAsyncContextFunction · 0.85
runInAsyncScopeMethod · 0.80
emitDestroyMethod · 0.80
onEndMethod · 0.80
deleteMethod · 0.65

Tested by

no test coverage detected