How to subscribe to event emitter once?

A call to subscribe returns an instance of Disposable, which has a method dispose. Or if you are using RxJS 5, dispose has been renamed to unsubscribe (thanks @EricMartinez). And from the RxJS docs: …when we’re no longer interested in receiving the data as it comes streaming in, we call dispose on our subscription. Store … Read more

How to unsubscribe from EventEmitter in Angular 2?

EventEmitter extends Subject. When you subscribe to a subject you get a Subscription which you can later use to unsubscribe. someOutput:EventEmitter = new EventEmitter(); … this.subscription = someOutput.subscribe(…); … this.subscription.unsubscribe(); Hint Don’t use EventEmitter for anything else but @Output()s. Angular doesn’t guarantee that EventEmitter will keep extending Subject or even work similar to a Subject … Read more

Concatenate two (or n) streams

This can be done with vanilla Node.js import { PassThrough } from ‘stream’ const merge = (…streams) => { let pass = new PassThrough() for (let stream of streams) { const end = stream == streams.at(-1); pass = stream.pipe(pass, { end }) } return pass } Use streams.slice(-1)[0] if you don’t have .at() in your … Read more

How to properly remove event listeners in node js eventemitter

You should name the function you attach as event handler. Then on removing it, you just pass the function by name: app.get(‘/api/:boardname/remoterefresh’, function(req, res){ var boardname = req.param(‘boardname’) function refreshHandler(data){ setTimeout(function(){ res.write(‘data: ‘+data+’\n\n’); }, 1000) } rr.on(“refresh-“+boardname, refreshHandler); req.socket.setTimeout(Infinity); res.writeHead(200, { ‘Content-Type’: ‘text/event-stream’, ‘Cache-Control’: ‘no-cache’, ‘Connection’: ‘keep-alive’ }); res.write(‘\n’); req.on(‘close’, function(){ console.log(‘closed’) rr.removeListener(“refresh-“+boardname, refreshHandler); }); … Read more

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

It turns out that this is a bug in nodejs core, we are talking about this problem here : https://github.com/joyent/node/issues/5108 Solution for bugged http servers thats throw an EventEmitter memory leak detected and fill up the available memory / available CPU times : Revert to legacy version v0.8.23. (You can download and install/compile it from … Read more

Is there any EventEmitter in browser side that has similar logic in NodeJS?

In modern browsers, there is EventTarget. class MyClass extends EventTarget { doSomething() { this.dispatchEvent(new Event(‘something’)); } } const instance = new MyClass(); instance.addEventListener(‘something’, (e) => { console.log(‘Instance fired “something”.’, e); }); instance.doSomething(); Additional Resources: Maga Zandaqo has an excellent detailed guide here: https://medium.com/@zandaqo/eventtarget-the-future-of-javascript-event-systems-205ae32f5e6b MDN has some documentation: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget Polyfill for Safari and other incapable browsers: … Read more

Pass parameters with EventEmitter

EventEmitter supports one argument, which is passed as $event to your event handler. Wrap your parameters in an event object when you pass it to emit: this.stopSort.emit({ event:event, ui: ui }); Then, when you handle the event, use $event: stopSort($event) { alert(‘event param from Component: ‘ +$event.event); alert(‘ui param from Component: ‘ + $event.ui); } … Read more

techhipbettruvabetnorabahisbahis forumueduedueduseduedueduedueduseduedus