I'm quite new to this RX stuff so forgive me if there something simple I'm missing here.
I was trying to use scan and found that it did not behave as I expected. This code illustrates how:
publicclassScanIssue
{
publicstaticvoidmain(String[] args) throwsInterruptedException
{
PublishSubject<Integer> source = PublishSubject.create();
Func2<Integer, Integer, Integer> accumulator = newFunc2<Integer, Integer, Integer>()
{
@OverridepublicIntegercall(Integera, Integerb)
{
returna + b;
}
};
Observable<Integer> scan = Observable.scan(source, accumulator);
// Observable<Integer> scan = Observable.scan(source, 0, accumulator);print("A", scan);
print("B", scan);
print("C", scan);
// print("D", scan);// print("E", scan);Thread.sleep(1000);
source.onNext(1);
Thread.sleep(1000);
source.onNext(1);
}
privatestatic <T> voidprint(finalStringprefix, Observable<T> source)
{
source.subscribe(newAction1<T>()
{
@Overridepublicvoidcall(Ts)
{
System.out.println(prefix + ": " + s);
}
});
}
}I would expect it to output nothing on the first onNext and this on the second:
Where I don't care about the order of A,B & C.
But instead it outputs this on the first one:
and this on the second:
B can be any of A, B and C but always the same all 6 times.
- If I switch to the one with initial value it works as I expect
- The more subscriptions I add the worse it gets
- The type of source does not seem to matter (tried with a hand rolled one)
I'm quite new to this RX stuff so forgive me if there something simple I'm missing here.
I was trying to use scan and found that it did not behave as I expected. This code illustrates how:
I would expect it to output nothing on the first
onNextand this on the second:Where I don't care about the order of A,B & C.
But instead it outputs this on the first one:
and this on the second:
B can be any of A, B and C but always the same all 6 times.