Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created April 24, 2020 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaGarcia/56c1d0947c53f4c44dc427d3ee0ebb49 to your computer and use it in GitHub Desktop.
Save NyaGarcia/56c1d0947c53f4c44dc427d3ee0ebb49 to your computer and use it in GitHub Desktop.
Creating Observables with interval()
import { interval } from "rxjs";
// Observable will emit incremental numbers, one every second (1000ms)
const number$ = interval(1000);
// We didn't pass the interval size parameter, so default value is 0ms
const superFastNumber$ = interval();
number$.subscribe(console.log);
// Output: 0 1 2 3 4 5...
// Careful with this one, it will emit numbers very very quickly
superFastNumber$.subscribe(number => console.log(number));
// Output: O 1 2 3 4 5 6 7 8 9...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment