Skip to content
Source
Sign inSign up
Open History to see the last commit

hostYield.ts

11 lines667 Bytes

1import * as Effect from "effect/Effect";
2​
3// Effect's own yield resumes through `setImmediate` where the host defines it and a
4// zero-delay timer otherwise. React Native's `setImmediate` is a microtask shim, so
5// nothing from the host runs before the fiber resumes. A timer yields on every host;
6// a browser can pass a yield that its timer clamping and throttling do not slow.
7export const yieldToHostTimer = Effect.callback<void>((resume) => {
8 // @effect-diagnostics-next-line globalTimersInEffect:off - A host timer, not Effect.sleep, is the point.
9 const timer = setTimeout(() => resume(Effect.void), 0);
10 return Effect.sync(() => clearTimeout(timer));
11});