我重装一个模块是这样的:Node.js的重装模块错误
require('./module.js'); // require the module
delete require.cache('/module.js'); // delete module from cache
require('/module.js'); // re-require the module
但如果该模块包含像这样存在一个问题:
setInterval(function(){
console.log('hello!');
}, 1000);
我每次重装模块将调用新的setInterval
,但最后一个未关闭。
有什么方法可以知道每个模块的(长)运行功能,所以我可以在我再次需要它之前阻止它们?或者有什么建议,我该如何做这项工作?
我接受任何疯狂的想法。