Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. const customIntervalObservable = new Observable(observer => {
  2. let count = 0;
  3. setInterval( () => {
  4. //We can call the next method to emit a new value.
  5. observer.next(count);
  6. count++;
  7. if(count > 3) {
  8. observer.error(new Error('Count is greater 3!'));
  9. }
  10. }, 1000);
  11. });
  12.  
  13. this.firstObsSubscription = customIntervalObservable.subscribe(data => {
  14. console.log(data);
  15. }, error => {
  16. // to handler the error we need to pass another argument to subscribe
  17. console.log(error.message);
  18. });
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement