diff --git a/.changeset/large-dogs-ring.md b/.changeset/large-dogs-ring.md new file mode 100644 index 0000000000..22c908979e --- /dev/null +++ b/.changeset/large-dogs-ring.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +TestClock yield with setTimeout(0) diff --git a/packages/effect/src/TestClock.ts b/packages/effect/src/TestClock.ts index 286f9c92e6..e84ba76b1e 100644 --- a/packages/effect/src/TestClock.ts +++ b/packages/effect/src/TestClock.ts @@ -304,13 +304,21 @@ export class TestClockImpl implements TestClock { return Option.none() }) } + + private yieldTimer = core.async((resume) => { + const timer = setTimeout(() => { + resume(core.void) + }, 0) + return core.sync(() => clearTimeout(timer)) + }) + /** * Returns whether all descendants of this fiber are done or suspended. */ suspended(): Effect.Effect, void> { return pipe( this.freeze(), - core.zip(this.live.provide(pipe(effect.sleep(Duration.millis(5)), core.zipRight(this.freeze())))), + core.zip(pipe(this.yieldTimer, core.zipRight(this.freeze()))), core.flatMap(([first, last]) => Equal.equals(first, last) ? core.succeed(first) : @@ -328,7 +336,7 @@ export class TestClockImpl implements TestClock { pipe( this.suspended(), core.zipWith( - pipe(this.live.provide(effect.sleep(Duration.millis(10))), core.zipRight(this.suspended())), + pipe(this.yieldTimer, core.zipRight(this.suspended())), Equal.equals ), effect.filterOrFail(identity, constVoid),