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가 === '취소'"다음 상태에 도달하면 예외를 발생하는 방법에 대한 사투를 벌인거야.
그 어떤 힌트를 주셔서 감사합니다!
감사 루카스
당신이 필요로하는 어떤 조건 당신은 단지do()
을 사용하고과
Error
을 던질 수
이것은 작동하는 것 같습니다! – Lukas