mirror of
https://github.com/JonasunderscoreJones/api.jonasjones.dev.git
synced 2025-10-23 12:09:19 +02:00
Initial commit (by create-cloudflare CLI)
This commit is contained in:
commit
58a42872a0
1745 changed files with 741893 additions and 0 deletions
46
node_modules/exit-hook/index.js
generated
vendored
Normal file
46
node_modules/exit-hook/index.js
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
|
||||
const callbacks = new Set();
|
||||
let isCalled = false;
|
||||
let isRegistered = false;
|
||||
|
||||
function exit(exit, signal) {
|
||||
if (isCalled) {
|
||||
return;
|
||||
}
|
||||
|
||||
isCalled = true;
|
||||
|
||||
for (const callback of callbacks) {
|
||||
callback();
|
||||
}
|
||||
|
||||
if (exit === true) {
|
||||
process.exit(128 + signal); // eslint-disable-line unicorn/no-process-exit
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = callback => {
|
||||
callbacks.add(callback);
|
||||
|
||||
if (!isRegistered) {
|
||||
isRegistered = true;
|
||||
|
||||
process.once('exit', exit);
|
||||
process.once('SIGINT', exit.bind(null, true, 2));
|
||||
process.once('SIGTERM', exit.bind(null, true, 15));
|
||||
|
||||
// PM2 Cluster shutdown message. Caught to support async handlers with pm2, needed because
|
||||
// explicitly calling process.exit() doesn't trigger the beforeExit event, and the exit
|
||||
// event cannot support async handlers, since the event loop is never called after it.
|
||||
process.on('message', message => {
|
||||
if (message === 'shutdown') {
|
||||
exit(true, -128);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return () => {
|
||||
callbacks.delete(callback);
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue