How do i execute the following scenario in the browser with RxJs:
A small optimization to the excellent answer from @matt-burnell. You can replace the filter and take operators with the first operator as follows
Rx.Observable
.fromPromise(submitJobToQueue(jobData))
.flatMap(jobQueueData =>
Rx.Observable.interval(1000)
.flatMap(() => pollQueueForResult(jobQueueData.jobId))
.first(x => x.completed)
.map(() => 'Completed')
.timeout(60000, Rx.Observable.throw(new Error('Timeout')))
)
.subscribe(
x => console.log('Result', x),
x => console.log('Error', x)
);
Also, for people that may not know, the flatMap operator is an alias for mergeMap in RxJS 5.0.