UNPKG

@mangar2/shutdown

Version:

Implements graceful shutdown

36 lines (31 loc) 1.11 kB
/** * --------------------------------------------------------------------------------------------------- * This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3. It is furnished * "as is", without any support, and with no warranty, express or implied, as to its usefulness for * any purpose. * * Author: Volker Böhm * Copyright: Volker Böhm * --------------------------------------------------------------------------------------------------- */ const shutdown = require('@mangar2/shutdown') const UnitTest = require('@mangar2/unittest') const unitTest = new UnitTest(true) shutdown(async () => { unitTest.log('SIGINT received') unitTest.success('shutdown') await delay(1000) unitTest.log('safe shutdown') process.exit(0) }) function delay (milliseconds) { return new Promise(resolve => setTimeout(resolve, milliseconds)) } (async () => { console.log('Press ^C to test') for (let i = 0; i < 10; i++) { await delay(1000) unitTest.log('.') } unitTest.showResult(0) })()