Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created April 24, 2020 14:13
Show Gist options
  • Save NyaGarcia/e8bbb8d2b3fe1ad1315586fef4d514a9 to your computer and use it in GitHub Desktop.
Save NyaGarcia/e8bbb8d2b3fe1ad1315586fef4d514a9 to your computer and use it in GitHub Desktop.
Creating Observables with timer()
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