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