This looks like you can use the zip()
operator that emits the n
th item only when all its source Observables have emitted n
th item:
const one$ = Observable.from(['a1', 'a2', 'a3'], Scheduler.async);
const two$ = Observable.from(['b1'], Scheduler.async);
Observable.zip(one$, two$, (v1, v2) => v1)
.subscribe(val => console.log(val));
I'm adding Scheduler.async
only to simulate asynchronous behavior (for more info see combineLatest behaviour in Rxjs 5?)
This will print to console:
a1
This is ok only if you know the one$
will emit only once.
Eventually you can use combineLatest()
that needs all its source Observables to emit at least one item and then emits on any emission where you can ignore two$
with a selector function.
const one$ = Observable.from(['a1', 'a2', 'a3'], Scheduler.async);
const two$ = Observable.from(['b1', 'b2'], Scheduler.async);
Observable.combineLatest(one$, two$.take(1), (v1, v2) => v1)
.subscribe(val => console.log(val));
We know that we only want the first item from two$
, the rest can be ignored.
This will print to console:
a1
a2
a3