]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/services/timer.service.ts
import ceph 16.2.6
[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
6import { NgZoneSchedulerService } from './ngzone-scheduler.service';
7
8@Injectable({
9 providedIn: 'root'
10})
11export class TimerService {
12 readonly DEFAULT_REFRESH_INTERVAL = 5000;
13 readonly DEFAULT_DUE_TIME = 0;
14 constructor(private ngZone: NgZoneSchedulerService) {}
15
16 get(
17 next: () => Observable<any>,
18 refreshInterval: number = this.DEFAULT_REFRESH_INTERVAL,
19 dueTime: number = this.DEFAULT_DUE_TIME
20 ): Observable<any> {
21 return timer(dueTime, refreshInterval, this.ngZone.leave).pipe(
22 observeOn(this.ngZone.enter),
23 switchMap(next),
24 shareReplay({ refCount: true, bufferSize: 1 })
25 );
26 }
27}