Deno: Callback on exit
Asked Answered
C

1

5

How do you add a callback for the program exiting?

Implementation in nodejs:

process.on('exit', function (){
    console.log('Goodbye!');
});
Conlan answered 11/6, 2020 at 19:33 Comment(0)
L
8

You can use unload

globalThis.addEventListener("unload", () => {
   console.log('goodbye!');
});

setTimeout(() => console.log('before goodbye'), 1000);

It'll be triggered when calling Deno.exit() as well. You can check more about Program Lifecycle here.

Larimer answered 11/6, 2020 at 20:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.