Last active
March 13, 2021 22:58
-
-
Save ssougnez/91eb8b2ceeda66a2fa76c25c101e660a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from 'rxjs'; | |
const observable = new Observable<number>(observer => { | |
let x = 0; | |
const interval = setInterval(() => { | |
if (x === 5) { | |
observer.error('Oops'); | |
} | |
else { | |
observer.next(x++); | |
} | |
}, 1000); | |
return { | |
unsubscribe: () => clearInterval(interval) | |
} | |
}); | |
observable.subscribe(x => console.log(`${x} received`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment