eventemitter

Node.js - inheriting from EventEmitter

对着背影说爱祢 提交于 2019-11-27 17:04:27
I see this pattern in quite a few Node.js libraries: Master.prototype.__proto__ = EventEmitter.prototype; (source here ) Can someone please explain to me with an example, why this is such a common pattern and when it's handy? alessioalex As the comment above that code says, it will make Master inherit from EventEmitter.prototype , so you can use instances of that 'class' to emit and listen to events. For example you could now do: masterInstance = new Master(); masterInstance.on('an_event', function () { console.log('an event has happened'); }); // trigger the event masterInstance.emit('an

Angular 2 event broadcast

只愿长相守 提交于 2019-11-27 15:59:20
问题 New to Angular 2. I'm working on broadcast a event between same level component. Currently I know EventEmitter just can transfer a event to upper level component. I have checked this this link and know observable may be a way to solve my problem, but the sample in that url seems not work for me. Does anyone know how to use it(observable) for broadcast event or some other way to transfer event to same level components? 回答1: You just need to create some service that will emit messages on which

What is the difference between these two constructor patterns?

拜拜、爱过 提交于 2019-11-27 15:51:51
Function ConstrA () { EventEmitter.call(this); } util.inherits(ConstrA, EventEmitter); vs Function ConstrA() {} util.inherits(ConstrA, EventEmitter); Is there something that the EventEmitter.call(this) does that is required? Is there something that the EventEmitter.call(this) does that is required? Apparently , yes: function EventEmitter() { EventEmitter.init.call(this); } … EventEmitter.init = function() { this.domain = null; if (EventEmitter.usingDomains) { // if there is an active domain, then attach to it. domain = domain || require('domain'); if (domain.active && !(this instanceof domain

Child listens for parent event in Angular 2

时间秒杀一切 提交于 2019-11-27 09:39:00
问题 In angular docs there is a topic about listening for child events from parents. That's fine. But my purpose is something reverse!. In my app there is an 'admin.component' that holds the layout view of admin page (sidebar menu,task bar, status etc..). In this parent component I configured router system for changing the main view between other pages of administrator. The problem is for saving things after change, the user clicks on save button in task bar (that is placed in admin.component) and

NodeJS : How to debug “EventEmitter memory leak detected. 11 listeners added”

江枫思渺然 提交于 2019-11-26 23:40:33
How can I debug my application which throw this error: (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit. Trace at Socket.EventEmitter.addListener (events.js:160:15) at Socket.Readable.on (_stream_readable.js:653:33) at Socket.EventEmitter.once (events.js:179:8) at TCP.onread (net.js:527:26) I could not find the assumed leaking object for increasing listener limit by .setMaxListeners(0); SOLUTION (from fardjad and jan salawa) With jan salawa's searches I found a working library ( longjohn ) for increasing stack

Unable to figure out correct EventEmitter or Observable Syntax in Angular2 Services

♀尐吖头ヾ 提交于 2019-11-26 22:53:59
问题 I'm having a hard time finding much in the way of examples/guides for using observables in an Angular2 service. There is stuff for html templates binding with EventEmitter but that doesn't seem right for a service. One of the big driving themes is getting away from Promises in Angular2 but I can't seem to get the new syntax correct. What I'm Doing I have a FirebaseAuth Service that can be injected into other services or components. I have a function that does an async call to firebase, in my

Node.js - inheriting from EventEmitter

…衆ロ難τιáo~ 提交于 2019-11-26 18:50:40
问题 I see this pattern in quite a few Node.js libraries: Master.prototype.__proto__ = EventEmitter.prototype; (source here) Can someone please explain to me with an example, why this is such a common pattern and when it's handy? 回答1: As the comment above that code says, it will make Master inherit from EventEmitter.prototype , so you can use instances of that 'class' to emit and listen to events. For example you could now do: masterInstance = new Master(); masterInstance.on('an_event', function (

What is the difference between these two constructor patterns?

别说谁变了你拦得住时间么 提交于 2019-11-26 17:20:43
问题 Function ConstrA () { EventEmitter.call(this); } util.inherits(ConstrA, EventEmitter); vs Function ConstrA() {} util.inherits(ConstrA, EventEmitter); Is there something that the EventEmitter.call(this) does that is required? 回答1: Is there something that the EventEmitter.call(this) does that is required? Apparently, yes: function EventEmitter() { EventEmitter.init.call(this); } … EventEmitter.init = function() { this.domain = null; if (EventEmitter.usingDomains) { // if there is an active

NodeJS : How to debug “EventEmitter memory leak detected. 11 listeners added”

冷暖自知 提交于 2019-11-26 08:48:26
问题 How can I debug my application which throw this error: (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit. Trace at Socket.EventEmitter.addListener (events.js:160:15) at Socket.Readable.on (_stream_readable.js:653:33) at Socket.EventEmitter.once (events.js:179:8) at TCP.onread (net.js:527:26) I could not find the assumed leaking object for increasing listener limit by .setMaxListeners(0); SOLUTION (from fardjad and

possible EventEmitter memory leak detected

泪湿孤枕 提交于 2019-11-26 03:27:49
I am getting following warning: (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit. Trace: at EventEmitter.<anonymous> (events.js:139:15) at EventEmitter.<anonymous> (node.js:385:29) at Server.<anonymous> (server.js:20:17) at Server.emit (events.js:70:17) at HTTPParser.onIncoming (http.js:1514:12) at HTTPParser.onHeadersComplete (http.js:102:31) at Socket.ondata (http.js:1410:22) at TCP.onread (net.js:354:27) I wrote code like this in server.js: http.createServer( function (req, res) { ... }).listen(3013); How to fix