Files
bun.sh/test/js/node/process/process-onBeforeExit-keepAlive.js
Jarred Sumner aa8b832ef6 Implement process.on("beforeExit", cb) and process.on("exit", cb) (#3576)
* Support `process.on('beforeExit')` and `process.on('exit')`

* [bun:sqlite] Always call sqlite3_close on exit

* Update process.test.js

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-07-08 14:26:19 -07:00

19 lines
412 B
JavaScript

let counter = 0;
process.on("beforeExit", () => {
if (process._exiting) {
throw new Error("process._exiting should be undefined");
}
console.log("beforeExit:", counter);
if (!counter++) {
setTimeout(() => {}, 1);
}
});
process.on("exit", () => {
if (!process._exiting) {
throw new Error("process.on('exit') called with process._exiting false");
}
console.log("exit:", counter);
});