Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import {Subject} from "rxjs/Subject";
  2. import {combineLatest} from "rxjs/observable/combineLatest";
  3. import {Observable} from "rxjs/Observable";
  4.  
  5. const subj1: Subject<string> = new Subject<string>();
  6. const subj2: Subject<number> = new Subject<number>();
  7. const combined: Observable<any> = combineLatest(subj1, subj2);
  8. combined.subscribe((arg) => {
  9. console.log('combined');
  10. console.log(arg);
  11. }, () => {
  12. console.log('error')
  13. });
  14.  
  15. setTimeout(() => {
  16. console.log('first timer');
  17. subj1.next('hello');
  18. }, 1000);
  19.  
  20. setTimeout(() => {
  21. console.log('second timer');
  22. subj2.next(1);
  23. }, 2000);
  24.  
  25. setTimeout(() => {
  26. console.log('3rd timer');
  27. subj1.next('world');
  28. }, 3000);
  29.  
  30. setTimeout(() => {
  31. console.log('4th timer');
  32. subj1.error(new Error('stam'));
  33. }, 3000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement