1

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?

4

1 回答 1

0

不,我不知道。

您可以通过调用来移除发射器上的所有事件侦听器myEmitter.removeAllListeners()。至于清除超时和间隔,分别调用clearTimeout(timeoutName)clearInterval(intervalName)

例子:

var x = 0;
var myInterval = setInterval(function(){
  console.log('hello');
  if (x > 5) clearInterval(myInterval);
  x += 1;
},1000);

希望这会有所帮助。

于 2012-10-09T02:01:32.437 回答