Skip to content

Instantly share code, notes, and snippets.

@umutyerebakmaz
Last active November 28, 2023 15:51
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 umutyerebakmaz/b6f991fff5ccec370b97286d5138faad to your computer and use it in GitHub Desktop.
Save umutyerebakmaz/b6f991fff5ccec370b97286d5138faad to your computer and use it in GitHub Desktop.
RXJS time based functions
// bir sayine sonra bir değer üretir
const timer$ = timer(1000);
timer$.subscribe(value => {
console.log(value); // 0
});
// her bir saniyede bir artan değer üretir
const interval$ = interval(1000);
interval$.subscribe(value => {
console.log(value); // 0, 1, 2, 3, ...
});
// her değeri 1 saniye geciktirir
const delay$ = of(1, 2, 3).pipe(
delay(1000)
);
delay$.subscribe(value => {
console.log(value); // 1, 2, 3 (1 saniye sonra)
});
// countdown larda uygulanır geriye sayım yapar.
const countdownSeconds = 10;
const countDown$ = timer(0, 1000).pipe(
map(secondsRemaining => countdownSeconds - secondsRemaining),
take(countdownSeconds + 1)
);
countDown$.subscribe(seconds => {
console.log(seconds); // 10, 9, 8, ..., 1, 0
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment