t3-code-android-nightly/.repos/effect-smol/packages/effect/test/utils/gc.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

19 lines
638 B
TypeScript

import { Effect } from "effect"
export const getGc = async (): Promise<() => void> => {
const { setFlagsFromString } = await import("node:v8")
const { runInNewContext } = await import("node:vm")
setFlagsFromString("--expose_gc")
const collect = runInNewContext("gc") as () => void
setFlagsFromString("--no-expose_gc")
return collect
}
export const collectGarbage = Effect.promise(async () => {
const collect = await getGc()
// WeakRef targets remain alive until the current job ends, so collect across jobs.
for (let i = 0; i < 8; i++) {
await new Promise((resolve) => setTimeout(resolve, 0))
collect()
}
})