Node.js中可能发生的事件错误?(Possible event bug in Node.js?)

编程入门 行业动态 更新时间:2024-10-26 18:16:13
Node.js中可能发生的事件错误?(Possible event bug in Node.js?)

我想我一直在遭受一个非常奇怪的错误。 使用EventEmitter可能会系统地破坏某些东西。 自从我开始使用once功能以来,事情似乎已经消失。

以下控制台输出行演示了正在发生的事情:

var EventEmitter = require('events').EventEmitter; a = new EventEmitter(); a.on("bla", function() { console.log("perm");}); a.once("bla", function() { console.log("this is temp"); }); a.emit('bla');

您可能希望调用这两个事件,但在我的控制台上输出为:

> a.emit("bla") perm perm true

这是怎么回事??

我也尝试在脚本中使用代码,这似乎有效,但我感觉到once功能在某种程度上导致了我服务器上的奇怪故障。

有没有遇到过这个?

[测试版本0.5.1和0.5.3]

I think I've been suffering from a very strange bug. There might be something systematically broken with EventEmitter. Ever since I started using the once function things seem off.

The following lines of console output demonstrate what's happening:

var EventEmitter = require('events').EventEmitter; a = new EventEmitter(); a.on("bla", function() { console.log("perm");}); a.once("bla", function() { console.log("this is temp"); }); a.emit('bla');

You would expect both events to be called, but on my console the output is:

> a.emit("bla") perm perm true

What's going on??

I've also tried using the code in a script and that seemed to work but I'm getting the feeling that the once function is somehow responsible for the weird glitches on my server.

Anyone ever encountered this?

[Tested on versions 0.5.1 and 0.5.3]

最满意答案

适用于我的0.5.10。 我很确定你输入的内容不是你发布的内容 - 第二个“烫发”来自哪里? 再试一次。

$ node > var EventEmitter = require('events').EventEmitter; > a = new EventEmitter(); {} > a.on("bla", function() { console.log("perm");}); { _events: { bla: [Function] } } > a.once("bla", function() { console.log("this is temp"); }); { _events: { bla: [ [Function], [Object] ] } } > a.emit('bla'); perm this is temp true >

Works for me on 0.5.10. I'm pretty sure you typed something else than what you posted here - where could the second "perm" come from? Try it again.

$ node > var EventEmitter = require('events').EventEmitter; > a = new EventEmitter(); {} > a.on("bla", function() { console.log("perm");}); { _events: { bla: [Function] } } > a.once("bla", function() { console.log("this is temp"); }); { _events: { bla: [ [Function], [Object] ] } } > a.emit('bla'); perm this is temp true >

更多推荐

本文发布于:2023-07-08 19:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080005.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可能发生   错误   事件   js   Node

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!