检查debounceTime()进度是否可观察

时间:2019-10-04 14:48:55

标签: javascript typescript rxjs observable subject

仅在退步中如何才能在.next()上执行Subject

let someFlag = true;
if (someFlag) {
    someFlag = false;
        if (this.resizeDebouncer !== null)) {
            this.resizeDebouncer = new Subject<Event>();
            this.resizeDebouncer.pipe(
                debounceTime(1000)
            ).subscribe(e => console.log(e.type));
        }

    }
this.resizeDebouncer.next(event); // should be executed only if resizeDebouncer subject in debouncing progress. 
// Don't execute if nothing is running

1 个答案:

答案 0 :(得分:0)

我没有发现任何要进行反跳的标记。 .isClosed.isStopped都不适合。但是我已经通过每次订阅内部退订Subject来解决了我的问题。在这种情况下,订阅仅存在于反跳进度范围内,而其他时间.next()则不执行任何操作。

let subscription = this.resizeDebouncer
    .pipe(debounceTime(300))
    .subscribe(e => {
        subscription.unsubscribe();
        e => console.log(e.type);
    });