Skip to content

Instantly share code, notes, and snippets.

@nlharri
Created November 15, 2018 16:23
Show Gist options
  • Save nlharri/5ca078b44001e4743c4024e4feedce3a to your computer and use it in GitHub Desktop.
Save nlharri/5ca078b44001e4743c4024e4feedce3a to your computer and use it in GitHub Desktop.
RxJS Tutorial - Hello World! - Observable subscribe with object
const { Observable } = require('rxjs');
// Create an Observable
var observable = Observable.create((observer) => {
observer.next('Hello World!');
observer.next('Hello Again!');
observer.complete();
observer.next('Bye'); // this will not be shown
});
// Subscribe to the Observable, and print stream to the console
observable.subscribe({
next: function(x) { console.log('next: ' + x) },
error: function(error) { console.log('error: ' + error) },
complete: function() { console.log('completed') }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment