什么是 Typescript / Angular 7(异步)相当于 setTimeout()

What is the Typescript / Angular 7 (asynchronous) equivalent to setTimeout()

我想为我的聊天应用程序构建一个 "typing indicator"。我目前正在尝试让指示器在用户停止按下任意键 5 秒后立即消失。

这样做的 Angular 方法是什么?

假设用户的输入在流中,称其为userTypingStream$,

userTypingStream$.pipe(
   (debounceTime(5000)
).subscribe(() => this.displayIndicator = false);

要创建这样的流:

private userTypingStream$: Subject<string> = new Subject();
//...
onKeyPress = (event) => {
   this.userTypingStream$.next(event.target.value);
   //... and possibly the rest of the keypress handler here.
}

相关主题:可观察对象和主题(开发 Angular 应用程序时几乎不可避免)。这些似乎是一个不错的起点:

https://angular.io/guide/observables

https://ncjamieson.com/understanding-subjects/