Files
bun.sh/test/js/node/async_hooks/async-context/async-context-crypto-randomFill.js
2025-07-02 17:45:00 -07:00

16 lines
481 B
JavaScript

const { AsyncLocalStorage } = require("async_hooks");
const crypto = require("crypto");
const asyncLocalStorage = new AsyncLocalStorage();
asyncLocalStorage.run({ test: "crypto.randomFill" }, () => {
const buffer = Buffer.alloc(16);
crypto.randomFill(buffer, (err, buf) => {
if (asyncLocalStorage.getStore()?.test !== "crypto.randomFill") {
console.error("FAIL: crypto.randomFill callback lost context");
process.exit(1);
}
process.exit(0);
});
});