Closed
Description
This C# snippet
var o = Observable.Concat(
Observable.Interval(TimeSpan.FromMilliseconds(500)).Take(2),
Observable.Interval(TimeSpan.FromMilliseconds(500)).Take(2)
);
o.Subscribe(x => Console.WriteLine("a: " + x), t => Console.WriteLine(t), () => Console.WriteLine("a: done"));
o.Subscribe(x => Console.WriteLine("b: " + x), t => Console.WriteLine(t), () => Console.WriteLine("b: done"));
Console.WriteLine("all subscribed");
Thread.Sleep(5000);
outputs, as expected, this:
all subscribed
b: 0
a: 0
b: 1
a: 1
a: 0
b: 0
a: 1
a: done
b: 1
b: done
The same translated to Java:
Action1<Long> printNext(final String who) {
return new Action1<Long>() {
public void call(Long o) {
System.out.println(who + o);
}
};
}
Action1<Throwable> printErr(final String who) {
return new Action1<Throwable>() {
public void call(Throwable o) {
System.out.println(who + o);
}
};
}
Action0 printComplete(final String who) {
return new Action0() {
public void call() {
System.out.println(who + "done");
}
};
}
@Test public void testConcat2() throws Exception {
Observable<Long> o = Observable.concat(
Observable.interval(500, TimeUnit.MILLISECONDS).take(2),
Observable.interval(500, TimeUnit.MILLISECONDS).take(2)
);
o.subscribe(printNext("a: "), printErr("a: "), printComplete("a: "));
o.subscribe(printNext("b: "), printErr("b: "), printComplete("b: "));
System.out.println("all subscribed");
Thread.sleep(5000);
}
only outputs this:
all subscribed
a: 0
a: 1
a: 0
a: 1
a: done
If I replace the Observable.interval
by an Observable.from
, the problem disappears, so I think the problem only shows up if we have concat + concurrency + multiple subscribers.
Metadata
Metadata
Assignees
Labels
No labels