java - RxJava- performing a peek() or void operation within an Observable chain? -
java 8 lambda streams have peek()
operator allows execute void operation on each item. typically used debugging, nice way cheat , kick off void operation without mapping something.
is there equivalent in rxjava? maybe i'm not following practice or thinking reactively enough... handy create status labels before , after operation? if peek()
not supported, there better pattern follow?
observable<item> item= ...; label statuslabel = new label(); label resultlabel = new label(); observable<calculateditem> calculateditem = calculated.subscribeon(schedulers.computation()) .peek(c -> statuslabel.settext("working..")) .map(c -> performexpensivecalculation(c)) .peek(r -> statuslabel.settext("")); calculateditem.subscribe(c -> resultlabel.settext(c));
there method doonnext(action1<item> action)
called each item in stream.
Comments
Post a Comment