rx java - Can each subscriber get different values from one Flowable? -
when subscribers subscribe 1 flowable , flowable emit items subscribers, can each subscriber different value?
for example, if flowable emits
0, 1, 2, 3...
one observer gets 0, 2 , other observer 1, 3, , on, load balancer.
how solution ?
@test public void testflowableloadbalancer() { intstream stream = intstream.iterate(1, -> + 1); flowable<integer> flowable = flowable.create(e -> stream.foreach(i -> { try { thread.sleep(1000); } catch (interruptedexception ignored) { } e.onnext(i); }), backpressurestrategy.drop); connectableflowable<integer> cf = flowable.publish(); cf.filter(i -> % 2 == 0).subscribe(i -> { logger.info("[even] = {}" , i); }); cf.filter(i -> % 2 == 1).subscribe(i -> { logger.info("[ odd] = {}" , i); }); cf.connect(); }
the output :
2016-11-11 18:15:57,884 info data.rx2test - [ odd] = 1 2016-11-11 18:15:58,892 info data.rx2test - [even] = 2 2016-11-11 18:15:59,895 info data.rx2test - [ odd] = 3 2016-11-11 18:16:00,900 info data.rx2test - [even] = 4
problem unsolved : cannot auto balance , pending other answers.
Comments
Post a Comment