Node.js事件流:在哪里setMaxListeners? [英] Node.js event-stream: Where to setMaxListeners?

查看:1633
本文介绍了Node.js事件流:在哪里setMaxListeners?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜查过这个,无济于事。我已经梳理了网络(包括Stackoverflow)和Node文档以找到答案,但没有找到一个---有效的(也许这只是我的错误搜索)。我正在使用gulp配置文件中的事件流,并且我有一个特殊任务正在触发EventEmitter类中经典的检测到内存泄漏错误。从我发现的问题来看,处理这个问题的答案似乎是调用EventEmitter类的setMaxListeners方法;我的研究表明事件流有一个Stream对象,它应该是EventEmitter的一个实例。然而,我试图调用setMaxListeners的方法,我没有找到方法。在仔细研究这个问题之后,我想我会把它带到这里的Node专家(我认为这很简单,而我只是缺少一些东西)。这是我的代码:

  return eventStream.merge(
gulp.src('./ jscript / libs / file- ('./ jscript / libs / filder_one / file-two.js'),
gulp.src('./ jscript / libs / folder_two / file- $'$ j $'gulp.src('./ jscript / libs / folder_three / file_four.js'),
gulp.src('./ jscript / libs / folder_four / file_five.js' ),
gulp.src('./ jscript / libs / folder_five / file_six.js'),
gulp.src('./ jscript / libs / file_seven.js'),
gulp.src('./ jscript / libs / file_eight.js'),
gulp.src('./ jscript / lists / rules / *。js')

.pipe (concat('my_file.js'))
.pipe(gulp.dest('./ jscript / dist /'))
.pipe(rename('my_file.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./ jscript / dist /'));

谢谢!

解决方案

这不是对你的问题的直接回答,但是你可以将一组glob模式传递给'gulp.src()',而不是合并多个'gulp.src()'。这难道不能解决你的问题吗?

https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulpsrcglobs-options



编辑

作为直接答案,以下内容适用于我:

  var merged = eventStream.merge(...); 
merged.setMaxListeners(0);
返回merged.pipe(...);

虽然事件侦听器被添加到合并函数中,但侦听器计数似乎在事件循环。所以我们可以在添加侦听器后马上设置MaxListeners。


I have searched and searched for this, to no avail. I've combed the web (including Stackoverflow), and the Node docs for an answer, and not found one---that worked (maybe that's just bad searching on my part). I'm working with an event-stream in a gulp config file, and I have a particular task that is hitting the classic "memory leak detected" error from the EventEmitter class. From what I've found, the answer to dealing with this issue seems to be to call the setMaxListeners method of the EventEmitter class; and my research has suggested that the event-stream has a Stream object, which should be an instance of EventEmitter. However, what ever way I try to call setMaxListeners, I get method not found. After exhausting myself researching the issue, I figured I'd bring it to the Node gurus here (I'm assuming this is simple, and I'm just missing something). Here's my code:

return eventStream.merge(
        gulp.src('./jscript/libs/file-one.js'),
        gulp.src('./jscript/libs/filder_one/file-two.js'),
        gulp.src('./jscript/libs/folder_two/file-three.js'),
        gulp.src('./jscript/libs/folder_three/file_four.js'),
        gulp.src('./jscript/libs/folder_four/file_five.js'),
        gulp.src('./jscript/libs/folder_five/file_six.js'), 
        gulp.src('./jscript/libs/file_seven.js'),
        gulp.src('./jscript/libs/file_eight.js'),
        gulp.src('./jscript/lists/rules/*.js')
    )        
    .pipe(concat('my_file.js'))
    .pipe(gulp.dest('./jscript/dist/'))
    .pipe(rename('my_file.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('./jscript/dist/'));

Thanks!

解决方案

This is not a direct answer to your question, but you can pass an array of glob patterns to 'gulp.src()' instead of merging multiple 'gulp.src()'s. Doesn't it solve your problem?

https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulpsrcglobs-options

EDIT

As a direct answer, the following worked for me:

var merged = eventStream.merge(...);
merged.setMaxListeners(0);
return merged.pipe(...);

While event listeners are added in the merge function, the listener count seems to be checked between ticks of the event loop. So we can setMaxListeners right after adding listeners.

这篇关于Node.js事件流:在哪里setMaxListeners?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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