You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var f=require.resolve('./functions.js');if(require.cache[f]){if(require.cache[f].exports.unload) require.cache[f].exports.unload();delete require.cache[f];}f=require(f);
also i suggest in this code unload event for a module
var f=require.resolve('./functions.js');
if(require.cache[f])
{
if(require.cache[f].exports.unload) require.cache[f].exports.unload()
delete require.cache[f];
}
f=require(f);
in the module
exports.unload=function(cb)
{
//
save_data();
//
if(cb)cb();
}
// exmple saving code:
var last_saved=new Date();
var last_activity=new Date();
var saveing_data=false;
function save_data()
{
if(last_activity<=last_saved) return;
if(saveing_data) return;
saveing_data=true;
//actualy save data here
console.log("data saved")
require('fs').writeFileSync(__dirname+'/data.json',"text"+(new Date()));
///
last_saved=new Date();
saveing_data=false;
}
setInterval(save_data,10000);
in the app:
function handleexit(cb)
{
var fs=Object.keys(require.cache)
function loop()
{
if(fs.length==0){cb();return;}
var f=fs.pop();
if(require.cache[f].exports.unload)
require.cache[f].exports.unload(loop)
else
loop()
}
loop();
}
process.on('SIGTERM', function () {
console.log('Got SIGTERM, will exit in 10 seconds ');
var num=1;
var n=setInterval(function(){
console.log(num)
num++;
},1000);
var c=setTimeout(function(){
if(n)clearTimeout(n);
process.exit(0);
},10000)
handleexit(function(){
if(c)clearTimeout(c);
if(n)clearTimeout(n);
process.exit(0);
})
});
process.on('SIGINT', function () {
console.log('Got SIGINT, will exit in 10 seconds ');
var num=1;
var n=setInterval(function(){
console.log(num)
num++;
},1000);
var c=setTimeout(function(){
if(n)clearTimeout(n);
process.exit(0);
},10000)
handleexit(function(){
if(c)clearTimeout(c);
if(n)clearTimeout(n);
process.exit(0);
})
});
The text was updated successfully, but these errors were encountered:
this is a one-liner for each time reload a file
also i suggest in this code unload event for a module
in the module
in the app:
The text was updated successfully, but these errors were encountered: