我有一个Node.js游戏服务器,通过运行nodemon app.js启动。现在,每当我编辑文件时,服务器就会重新启动。我已经实现了保存和加载功能,并且希望每次游戏服务器由于文件更改而重新启动时,在重新启动之前保存游戏状态,以便重启后可以加载先前的状态。
我想要的是这样的东西:
我想要的是这样的东西:
process.on('restart', function(doneCallback) {
saveGame(doneCallback);
// The save game is async because it is writing toa file
}
我尝试使用SIGUR2
事件,但它从未被触发。这是我的尝试,但该函数从未被调用。
// Save game before restarting
process.once('SIGUSR2', function () {
console.log('SIGUR2');
game.saveGame(function() {
process.kill(process.pid, 'SIGUSR2');
});
});
nodemon.on('restart',...)
吗? - crackmiggnodemon
包,我会看一下。 - XCS