RxJS计时器重置

时间:2019-04-25 13:04:40

标签: javascript angular rxjs

我的Angular应用中有以下计时器:

const sessionWarntime = this.config.sessionWarntime ? 
this.config.sessionWarntime * 1000 : 240000; // time before session end 
this.warntimer = timer(this.sessionTime - sessionWarntime);
this.warntimerSubscriber();

这是订户方法代码:

private warntimerSubscriber() {
this.warntimer.pipe(
  first()
).subscribe((res: number) => {
  if (res === 0) {
    // Time to session end in minutes
    const sessionWarntime = this.config.sessionWarntime ? 
    this.config.sessionWarntime : 240;
    const min = sessionWarntime / 60;
    this.sessionWarning.emit(min.toString());
  }
});

}

现在,如果用户处于活动状态,我想重置此计时器,但是我该怎么做?以下行将创建一个新计时器:

 this.warntimer = timer(this.sessionTime - sessionWarntime);

0 个答案:

没有答案