我有一个Observable每x秒调用一次。
和两个名为Start和Stop 的按钮来控制 observable。
我想在用户按下停止按钮时停止进程并取消订阅,并在按下开始后每x秒开始获取数据
到目前为止我有:
public subscription: Subscription;
public isLoading: boolean = false;
public isStopped: boolean = true;
// Start Getting Data
getData() {
this.isStopped = false;
this.isLoading = true;
this.subscription = this.proxy.InternetUserRwaits(model).pipe(
repeatWhen(completed => {
return completed.pipe(
tap(_ => this.isLoading = false),
delay(this.interval * 1000),
tap(_ => this.isLoading = this.isStopped ? false : true),
);
}),
)
.subscribe(
result => {
this.isLoading = false; …Run Code Online (Sandbox Code Playgroud)