Skip to content

Instantly share code, notes, and snippets.

@nlharri
Last active October 19, 2022 10:30
Show Gist options
  • Save nlharri/109ee77bece7dadd75987c58fb079ea4 to your computer and use it in GitHub Desktop.
Save nlharri/109ee77bece7dadd75987c58fb079ea4 to your computer and use it in GitHub Desktop.
RxJS Tutorial - Event Emitter for Node JS
var EventEmitter = require('events').EventEmitter;
const { Observable, fromEvent } = require('rxjs');
var emitter = new EventEmitter();
var source = fromEvent(emitter, 'data');
var subscription = source.subscribe(
(x) => console.log('Next: ' + x),
(err) => console.log('Error: ' + err),
() => console.log('Completed'));
emitter.emit('data', 'My 1st emitted data');
emitter.emit('data', 'My 2nd emitted data');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment