From 1f8b83ba1aafd2c25c24c00eb7a117588a34b3f9 Mon Sep 17 00:00:00 2001 From: Steven Guerrero Date: Mon, 25 Jan 2021 11:30:31 -0500 Subject: feat(std/node): Add support for process.on("exit") (#8940) This commit adds support for process.on("exit") by appending a listener to the unload event. Luckily, unload works pretty much the same as on("exit") since it won't schedule any additional work in the even loop either. This commit also solves an error in the Node implementation, since "process.argv" didn't contained the main module route as it was supposed to. --- std/node/process_exit_test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 std/node/process_exit_test.ts (limited to 'std/node/process_exit_test.ts') diff --git a/std/node/process_exit_test.ts b/std/node/process_exit_test.ts new file mode 100644 index 000000000..54c8bcc01 --- /dev/null +++ b/std/node/process_exit_test.ts @@ -0,0 +1,19 @@ +import "./global.ts"; + +//deno-lint-ignore no-undef +process.on("exit", () => { + console.log(1); +}); + +function unexpected() { + console.log(null); +} +//deno-lint-ignore no-undef +process.on("exit", unexpected); +//deno-lint-ignore no-undef +process.removeListener("exit", unexpected); + +//deno-lint-ignore no-undef +process.on("exit", () => { + console.log(2); +}); -- cgit v1.2.3