Node.js中process.emit的事件范围 [英] Scope of events from process.emit in Node.js

查看:190
本文介绍了Node.js中process.emit的事件范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码发送这样的事件:

  process.emit('event',event); 

我想像这样听这些活动:

  process.on('event',function(event){
// HANDLING LOGIC
});

当文件位于同一文件夹中时,它的工作正常。当我将侦听器放在其他文件夹中时,它不会被触发。
什么可以是这个的根本原因,而我可以处理它?<​​/ p>

编辑:



实际的问题只是一个缺少的包含事件处理的文件。

解决方案

进程是一个单一的全局实例。范围不应与您的问题相关。



进程


I have code to sent event like this:

process.emit('event', event);

I would like to listen to these event like this:

process.on('event', function(event) {
     //HANDLING LOGIC
});

It works fine when files are located in the same folder. When I located listener in other folder it is not fired. What can be a root cause of this and hwo can I handle it?

EDIT:

The actual problem was just a missing expose with a file including event handling. Shame on me.

解决方案

The process is a single global instance. the scope should not be related to your problem.

process in node.js docs

这篇关于Node.js中process.emit的事件范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆