Z
Z
zlodiak2018-02-24 16:49:29
JavaScript
zlodiak, 2018-02-24 16:49:29

How to explain the addition of two asynchronous threads?

Is there any way to logically explain what happens in this code:

var b = Rx.Observable.interval(1000);
var a = Rx.Observable.interval(3000);
b.concat(a).subscribe((val) => console.log(val));


It is not clear why the console outputs consecutive numbers from zero to infinity. Although in fact here we are dealing with two independent streams emitting asynchronously at different intervals.

That is, the picture in the console should be something like this:
0
1
2
<b>1</b>
3
4
5
<b>2</b>
6
7
8

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-02-24
@zlodiak

As I understand it, you are fantasizing again instead of googling the documentation. It says in black and white :

next transaction (subscription) cannot start until the previous completes

If you want it to be "independent" - use merge instead of concat.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question