* Evaluates an effect until completion, potentially asynchronously. * * **NOTE**: This method must be invoked by the fiber itself.
(effect0: Effect.Effect<any, any, any>)
| 939 | * **NOTE**: This method must be invoked by the fiber itself. |
| 940 | */ |
| 941 | evaluateEffect(effect0: Effect.Effect<any, any, any>) { |
| 942 | this.currentSupervisor.onResume(this) |
| 943 | try { |
| 944 | let effect: Effect.Effect<any, any, any> | null = |
| 945 | runtimeFlags_.interruptible(this.currentRuntimeFlags) && this.isInterrupted() ? |
| 946 | core.exitFailCause(this.getInterruptedCause()) : |
| 947 | effect0 |
| 948 | while (effect !== null) { |
| 949 | const eff: Effect.Effect<any, any, any> = effect |
| 950 | const exit = this.runLoop(eff) |
| 951 | if (exit === YieldedOp) { |
| 952 | const op = yieldedOpChannel.currentOp! |
| 953 | yieldedOpChannel.currentOp = null |
| 954 | if (op._op === OpCodes.OP_YIELD) { |
| 955 | if (runtimeFlags_.cooperativeYielding(this.currentRuntimeFlags)) { |
| 956 | this.tell(FiberMessage.yieldNow()) |
| 957 | this.tell(FiberMessage.resume(core.exitVoid)) |
| 958 | effect = null |
| 959 | } else { |
| 960 | effect = core.exitVoid |
| 961 | } |
| 962 | } else if (op._op === OpCodes.OP_ASYNC) { |
| 963 | // Terminate this evaluation, async resumption will continue evaluation: |
| 964 | effect = null |
| 965 | } |
| 966 | } else { |
| 967 | this.currentRuntimeFlags = pipe(this.currentRuntimeFlags, runtimeFlags_.enable(runtimeFlags_.WindDown)) |
| 968 | const interruption = this.interruptAllChildren() |
| 969 | if (interruption !== null) { |
| 970 | effect = core.flatMap(interruption, () => exit) |
| 971 | } else { |
| 972 | if (this._queue.length === 0) { |
| 973 | // No more messages to process, so we will allow the fiber to end life: |
| 974 | this.setExitValue(exit) |
| 975 | } else { |
| 976 | // There are messages, possibly added by the final op executed by |
| 977 | // the fiber. To be safe, we should execute those now before we |
| 978 | // allow the fiber to end life: |
| 979 | this.tell(FiberMessage.resume(exit)) |
| 980 | } |
| 981 | effect = null |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | } finally { |
| 986 | this.currentSupervisor.onSuspend(this) |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | /** |
| 991 | * Begins execution of the effect associated with this fiber on the current |
no test coverage detected