Concat VS Merge function in RxJS

merge can interleave the outputs, while concat will first wait for earlier streams to finish before processing later streams

Observable.merge(
        Observable.interval(1, TimeUnit.SECONDS).map(id -> "A" + id),
        Observable.interval(1, TimeUnit.SECONDS).map(id -> "B" + id))
.subscribe(System.out::println);
A0 B0 A1 B1 B2 A2 B3 A3 B4 A4

Observable.concat(
        Observable.interval(1, TimeUnit.SECONDS).map(id -> "A" + id),
        Observable.interval(1, TimeUnit.SECONDS).map(id -> "B" + id))
.subscribe(System.out::println);
A0 A1 A2 A3 A4 A5 A6 A7 A8

References
https://stackoverflow.com/questions/38903094/concat-vs-merge-operator
https://rxjs.dev/api/index/function/merge
https://rxjs.dev/api/index/function/concat