Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
hotfix avoid loop while yielding (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikearnaldi authored Sep 29, 2023
1 parent 9457256 commit d1bf3e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-ligers-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/io": patch
---

Avoid loops while yielding
18 changes: 12 additions & 6 deletions src/internal/fiberRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export class FiberRuntime<E, A> implements Fiber.RuntimeFiber<E, A> {
public _scheduler: Scheduler
private _tracer: Tracer.Tracer
public currentOpCount: number = 0
private isYielding = false

constructor(
fiberId: FiberId.Runtime,
Expand Down Expand Up @@ -1235,6 +1236,7 @@ export class FiberRuntime<E, A> implements Fiber.RuntimeFiber<E, A> {
}

[OpCodes.OP_YIELD](op: core.Primitive & { op: OpCodes.OP_YIELD }) {
this.isYielding = false
throw op
}

Expand Down Expand Up @@ -1269,12 +1271,16 @@ export class FiberRuntime<E, A> implements Fiber.RuntimeFiber<E, A> {
if (this._queue.length > 0) {
cur = this.drainQueueWhileRunning(this._runtimeFlags, cur)
}
this.currentOpCount += 1
const shouldYield = this._scheduler.shouldYield(this)
if (shouldYield !== false) {
this.currentOpCount = 0
const oldCur = cur
cur = core.flatMap(core.yieldNow({ priority: shouldYield }), () => oldCur)
if (!this.isYielding) {
const shouldYield = this._scheduler.shouldYield(this)
if (shouldYield !== false) {
this.isYielding = true
this.currentOpCount = 0
const oldCur = cur
cur = core.flatMap(core.yieldNow({ priority: shouldYield }), () => oldCur)
} else {
this.currentOpCount += 1
}
}
try {
if (!((cur as core.Primitive)._tag in this)) {
Expand Down

0 comments on commit d1bf3e7

Please sign in to comment.