]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/services/timer.service.ts
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / services / timer.service.ts
CommitLineData
1911f103
TL
1import { Injectable } from '@angular/core';
2
3import { Observable, timer } from 'rxjs';
4import { observeOn, shareReplay, switchMap } from 'rxjs/operators';
5
2a845540 6import { whenPageVisible } from '../rxjs/operators/page-visibilty.operator';
1911f103
TL
7import { NgZoneSchedulerService } from './ngzone-scheduler.service';
8
9@Injectable({
10 providedIn: 'root'
11})
12export class TimerService {
13 readonly DEFAULT_REFRESH_INTERVAL = 5000;
14 readonly DEFAULT_DUE_TIME = 0;
15 constructor(private ngZone: NgZoneSchedulerService) {}
16
17 get(
18 next: () => Observable<any>,
19 refreshInterval: number = this.DEFAULT_REFRESH_INTERVAL,
20 dueTime: number = this.DEFAULT_DUE_TIME
21 ): Observable<any> {
22 return timer(dueTime, refreshInterval, this.ngZone.leave).pipe(
23 observeOn(this.ngZone.enter),
24 switchMap(next),
2a845540
TL
25 shareReplay({ refCount: true, bufferSize: 1 }),
26 whenPageVisible()
1911f103
TL
27 );
28 }
29}