2
我确实编写了一个Observable,它正在轮询返回特定值后完成的URL。rxjs在http请求返回特定值时抛出错误
private checkPairingStatus(paringModel: any): Observable<ResponseObject> {
let data = { id: 1234 };
return Observable
.interval(2000)
.switchMap(() => this.get<ResponseObject>('http://api/getstatus', data))
.first(r => r.Status === 'success') // once our pairing is active we emit that
.timeout(90000, Observable.throw(new Error('Timeout ocurred')));
// todo: find a way to abort the interval once the PairingStatus hits the 'canceled' status.
}
这工作得很好,但我挣扎于如何一次我的输入反应例如点击下面的状态“r.Status ===‘取消’”抛出异常。
感谢您的任何提示!
问候 卢卡斯
tnx这似乎工作! – Lukas