Files
bun.sh/test/js/node/async_hooks/async-context/async-context-timers-ref-unref.js
2025-07-02 17:45:00 -07:00

18 lines
474 B
JavaScript

const { AsyncLocalStorage } = require("async_hooks");
const asyncLocalStorage = new AsyncLocalStorage();
asyncLocalStorage.run({ test: "timers.ref.unref" }, () => {
const timeout = setTimeout(() => {
if (asyncLocalStorage.getStore()?.test !== "timers.ref.unref") {
console.error("FAIL: setTimeout with ref/unref lost context");
process.exit(1);
}
process.exit(0);
}, 10);
// Test ref/unref operations
timeout.unref();
timeout.ref();
});