SHARE
TWEET

Untitled

a guest Sep 17th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top