1 import { setInterval } from 'timers'
2 import { Component, OnInit, OnDestroy } from '@angular/core';
4 import { RequestService, RequestStats } from '../shared';
7 selector: 'my-request-stats',
8 templateUrl: './request-stats.component.html',
9 styleUrls: [ './request-stats.component.scss' ]
11 export class RequestStatsComponent implements OnInit, OnDestroy {
12 stats: RequestStats = null;
14 private interval: NodeJS.Timer = null;
16 constructor(private requestService: RequestService) { }
24 if (this.stats !== null && this.stats.secondsInterval !== null) {
25 clearInterval(this.interval);
30 this.requestService.getStats().subscribe(
31 stats => this.stats = stats,
33 err => alert(err.text)
37 private runInterval() {
38 this.interval = setInterval(() => {
39 this.stats.remainingMilliSeconds -= 1000;
41 if (this.stats.remainingMilliSeconds <= 0) {
42 setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100);