Last active
October 19, 2022 10:30
-
-
Save nlharri/109ee77bece7dadd75987c58fb079ea4 to your computer and use it in GitHub Desktop.
RxJS Tutorial - Event Emitter for Node JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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