我重裝一個模塊是這樣的: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
,但最後一個未關閉。
有什麼方法可以知道每個模塊的(長)運行功能,所以我可以在我再次需要它之前阻止它們?或者有什麼建議,我該如何做這項工作?
我接受任何瘋狂的想法。