Created
April 24, 2020 14:13
-
-
Save NyaGarcia/e8bbb8d2b3fe1ad1315586fef4d514a9 to your computer and use it in GitHub Desktop.
Creating Observables with timer()
This file contains hidden or 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 { timer } from "rxjs"; | |
// Observable will emit one value (0) after 2s and complete | |
const onlyOneValue$ = timer(2000); | |
// Observable will wait 5s, then start emitting values every second | |
const number$ = timer(5000, 1000); | |
onlyOneValue$.subscribe(console.log); | |
// Output: 0 | |
number$.subscribe(number => console.log(number)); | |
// Output: 0, 1, 2, 3... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment