2
特定の値が返されると完了するURLをポーリングするObservableを書きました。HTTPリクエストが特定の値を返すと、rxjsがエラーをスローする
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.
}
これはかなりうまく動作しますが、例えば、私のresponeは、以下のステータス当たったら私は「r.Statusを=== 『キャンセル』」例外をスローする方法について苦労しています。
ありがとうございました!
よろしく ルーカス
これは動作するようです! – Lukas