Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {concat} from "rxjs/observable/concat";
- import {Subject} from "rxjs/Subject";
- import {Observable} from "rxjs/Observable";
- const subOdd: Subject<number> = new Subject<number>();
- const subEven: Subject<number> = new Subject<number>();
- const mergedObservable: Observable<number> = concat(subEven, subOdd);
- mergedObservable.subscribe((value: number) => {
- console.log(value);
- }, () => {
- console.log('will error out if one of the observables errors')
- });
- subOdd.next(1); // will not print since subEven is not complete
- subOdd.next(3); // will not print since subEven is not complete
- subOdd.next(5); // will not print since subEven is not complete
- subEven.next(0); // will be printed
- subEven.next(2); // will be printed
- subEven.next(4); // will be printed
- subEven.complete();
- subOdd.next(7); // now it will be printed
- subOdd.next(9); // now it will be printed
- subOdd.error(new Error('Yet another error'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement