我如何才能在Subject上执行.next(),如果它处于去抖动的进程中?
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发布于 2019-10-05 01:19:45
我没有找到任何正在进行的去抖动的标记。无论是.isClosed还是.isStopped都不适合。但我已经解决了我的问题,每次在订阅内部都从Subject取消订阅。在这种情况下,订阅只存在于去抖动的进程范围内,而在其他情况下,.next()不做任何事情。
let subscription = this.resizeDebouncer
.pipe(debounceTime(300))
.subscribe(e => {
subscription.unsubscribe();
e => console.log(e.type);
});https://stackoverflow.com/questions/58238697
复制相似问题