I'm looking for a way to trigger application shutdown from a service in Nest.js that will still call hooks.
I have a case when I'm handling a message in a service and in some scenario this should shutdown the application. I used to throw unhandled exceptions but when I do this Nest.js doesn't call hooks like onModuleDestroy
or even shutdown hooks like onApplicationShutdown
which are required in my case.
calling .close()
from INestApplication
works as expected but how do I inject it into my service? Or maybe there is some other pattern I could use to achieve what I'm trying to do?
Thank you very much for all the help.