Is it possible to unload modules in nodejs?
In other words: clear event listeners, timeouts, and intervals.
These modules are "sub-files" of my project, and i could overwrite the .on()
, and .once()
, but what about timeouts and intervals?
Is it possible to unload modules in nodejs?
In other words: clear event listeners, timeouts, and intervals.
These modules are "sub-files" of my project, and i could overwrite the .on()
, and .once()
, but what about timeouts and intervals?
不,我不知道。
您可以通过调用来移除发射器上的所有事件侦听器myEmitter.removeAllListeners()
。至于清除超时和间隔,分别调用clearTimeout(timeoutName)
和clearInterval(intervalName)
。
例子:
var x = 0;
var myInterval = setInterval(function(){
console.log('hello');
if (x > 5) clearInterval(myInterval);
x += 1;
},1000);
希望这会有所帮助。