Deno: Callback on exit

Viewed 552

How do you add a callback for the program exiting?

Implementation in nodejs:

process.on('exit', function (){
    console.log('Goodbye!');
});
1 Answers

You can use unload

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

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

You can check more about Program Lifecycle here.

Unfortunately it won't be called if Deno.exit() is called. There's an open issue regarding this, and hopefully, it will be possible soon.

Related