Basic RxJS Observable

node v14.20.1
version: 4.0.0
endpointsharetweet
const rxjs = require('rxjs'); const { Observable } = rxjs const observable = new Observable(subscriber => { subscriber.next(1); subscriber.next(2); subscriber.next(3); subscriber.complete(); }); console.log('just before subscribe'); // Subscriber 1 observable.subscribe({ next(x) { console.log('sub1: got value ' + x); }, error(err) { console.error('sub1: something wrong occurred: ' + err); }, complete() { console.log('sub1: done'); } }); // Subscriber 2 observable.subscribe({ next(x) { console.log('sub2: got value ' + x); }, error(err) { console.error('sub2: something wrong occurred: ' + err); }, complete() { console.log('sub2: done'); } }); console.log('just after subscribe');
Loading…

no comments

    sign in to comment