java - RxJava computation explosion -
i'm facing tricky issue combinelatest. i'm building huge chain of combinelatest , starting second item main observable, there explosion of computation.
import org.testng.annotations.test; import rx.observable; import rx.observers.testsubscriber; import rx.subjects.publishsubject; import rx.subjects.subject; import java.util.list; import java.util.concurrent.atomic.atomicinteger; public class rxtest { private atomicinteger ai = new atomicinteger(0); private atomicinteger ai2 = new atomicinteger(0); @test public void explosion() { subject<integer, integer> sub = publishsubject.create(); observable<integer> ret = getobservable(2, sub); testsubscriber<integer> testsubscriber = new testsubscriber<integer>(); ret.subscribe(testsubscriber); sub.onnext(1); sub.onnext(2); // may commented sub.oncompleted(); testsubscriber.assertnoerrors(); list<integer> numbers = testsubscriber.getonnextevents(); system.out.println(numbers.size()); system.out.println(ai); system.out.println(ai2); } private observable<integer> getobservable(int depth, observable<integer> source) { if (depth == 0) { return source; } else { observable<integer> o = getobservable(depth - 1, source); (int = 0; < 300; ++i) { ai2.incrementandget(); o = observable.combinelatest( o, getobservable(depth - 1, source).map((a) -> { ai.incrementandget(); return a; }), (a, b) -> + b ); } return o; } } }
with 1 item, have:
1 90600 90600
with two:
90602 271200 90600
it seems normal behaviour of rx. i'm trying know if possible avoid kind of explosion. goal have kind of output (like recreate chain each value)
2 181200 90600
this code example of problem not real use case.
i'm facing fact building observable quick(and having first value observable) if i'm changing "leaf" observable, it's not.
thanks
Comments
Post a Comment