Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {timer, isObservable, of} from "rxjs";
- import {share, switchMap} from "rxjs/operators";
- function callHook$(hook$, freq) {
- const _hook$ = isObservable(hook$) ? hook$ : of(hook$);
- // freq must be int
- let _freq = Math.round(freq);
- return _freq > 0
- // share will kill the timer when no subscribers are left
- ? timer(0, Math.max(1000, _freq)).pipe(share(), switchMap(() => hook$))
- : hook$;
- }
Advertisement
Add Comment
Please, Sign In to add comment