Angular 6 双订阅问题

Angular 6 double subscribe issue

我想在我的应用程序空闲超时结束时发出刷新令牌 API 调用...

我这样做的错误代码是:

idle.onIdleEnd.subscribe(() => {
            console.log('idle end reached');
            if (this.authStore.isAuthenticated()) {
                this.authService.refreshToken().subscribe(() => null);
            }

            this.activeModal.hide();
        });

但是,出于某种原因,这会以指数方式触发刷新令牌,这是不可取的,并且最终会产生竞争条件,在已经发出新令牌(从本地存储读取)时发送无效令牌。

所以当空闲计时器触发一次并且我摆动鼠标时,刷新令牌触发一次,但是第二次触发两次,第三次触发 4 次,我如何让它在每个空闲端触发一次?

隐藏模态时尝试取消订阅可观察对象:

private subscription: Subscription;

this.subscription = idle.onIdleEnd.subscribe(() => {
    console.log('idle end reached');
    if (this.authStore.isAuthenticated()) {
        this.authService.refreshToken().subscribe();
    }

    this.activeModal.hide();
    this.subscription.unsubscribe();
});