(effect: Primitive)
| 703 | } |
| 704 | } |
| 705 | runLoop(effect: Primitive): Exit.Exit<A, E> | Yield { |
| 706 | const prevFiber = (globalThis as any)[currentFiberTypeId] |
| 707 | ;(globalThis as any)[currentFiberTypeId] = this |
| 708 | const prevRunning = this._running |
| 709 | this._running = true |
| 710 | let yielding = false |
| 711 | let resuming = this._autoYielded |
| 712 | this._autoYielded = false |
| 713 | let current: Primitive | Yield = effect |
| 714 | // Count the resumption as the exitVoid instruction it replaces. |
| 715 | this.currentOpCount = resuming ? 1 : 0 |
| 716 | try { |
| 717 | while (true) { |
| 718 | try { |
| 719 | if (this._deferredInterrupt) { |
| 720 | this._deferredInterrupt = false |
| 721 | current = failCause(this._interruptedCause!) as any |
| 722 | } |
| 723 | this.currentOpCount++ |
| 724 | // Refresh the cache because a primitive can replace the fiber context. |
| 725 | const cache = this.cache |
| 726 | // Only automatic resumptions must run their saved instruction before |
| 727 | // checking the budget; other slices retain their existing yield points. |
| 728 | if ( |
| 729 | !resuming && |
| 730 | !yielding && |
| 731 | !cache.preventYield && |
| 732 | cache.scheduler.shouldYield(this as any) |
| 733 | ) { |
| 734 | // If dispatch throws, evaluate its defect instead of retrying the yield. |
| 735 | yielding = true |
| 736 | current = this.yieldNow(current as Primitive, 0, true) |
| 737 | } else { |
| 738 | resuming = false |
| 739 | current = cache.tracerContext |
| 740 | ? cache.tracerContext(current as any, this) |
| 741 | : (current as any)[evaluate](this) |
| 742 | } |
| 743 | if (current === Yield) { |
| 744 | const yielded = this._yielded! |
| 745 | if (ExitTypeId in yielded) { |
| 746 | this._deferredInterrupt = false |
| 747 | this._yielded = undefined |
| 748 | return yielded |
| 749 | } else if (this._deferredInterrupt) { |
| 750 | this._yielded = undefined |
| 751 | yielded() |
| 752 | continue |
| 753 | } |
| 754 | return Yield |
| 755 | } |
| 756 | } catch (error) { |
| 757 | if (!hasProperty(current, evaluate)) { |
| 758 | this._stack.length = 0 |
| 759 | return exitDie(`Fiber.runLoop: Not a valid effect: ${String(current)}`) |
| 760 | } |
| 761 | current = exitDie(error) as any |
| 762 | } |
no test coverage detected