Shitbox2,
function sendRequest(val, until) {
let chaining = Rx.Observable.timer(0, 1000).switchMap(getData);
chaining = until ? chaining.takeUntil(Rx.Observable.timer(val)) : chaining.take(val);
return chaining
.find(data => data.id === 5)
.switchMap(data => data ? Rx.Observable.of(data) : Rx.Observable.throw('timeout'))
}
//Ошибка после 10 попыток
sendRequest(10)
.subscribe(data => console.log('next', data), error => console.log('error', error), () => console.log('complete'));
//Ошибка после 10 с.
sendRequest(10000, true)
.subscribe(data => console.log('next', data), error => console.log('error', error), () => console.log('complete'));