Skip to content

How can I make an observable based on 2 others, but emit only when the 2 observables emit new values #7112

Answered by josepot
MiniSuperDev asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @MiniSuperDev !

If I understood the question correctly, then I think that the operator that you are looking for is zip:

import { zip, of, delay, concatMap } from 'rxjs';

const observable1$ = of('a', 'a', 'b').pipe(
  concatMap((v) => of(v).pipe(delay(100)))
);
const observable2$ = of('1', '2', '3', '4').pipe(
  concatMap((v) => of(v).pipe(delay(100)))
);

zip(observabl1, observable2).subscribe(console.log);

Just be cautious of backpressure.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@MiniSuperDev
Comment options

@XuankangLin
Comment options

Comment options

You must be logged in to vote
2 replies
@MiniSuperDev
Comment options

@josepot
Comment options

Answer selected by MiniSuperDev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants