rx java - Take and debounce usage issue -


i have next test case

public void testlimitandpublishsubject() throws interruptedexception {     publishsubject<boolean> mbooleanpublishsubject = publishsubject.create();     mbooleanpublishsubject.asobservable()             .dooneach(__ -> system.out.println("on value emitted "+system.currenttimemillis()))             .take(1)             .dooneach(__ -> system.out.println("on value emitted 2 "+system.currenttimemillis()))             .debounce(1000, timeunit.milliseconds)             .dooneach(__ -> system.out.println("on value emitted 3 "+system.currenttimemillis()))             .subscribe(__ -> system.out.println("done "+system.currenttimemillis()));     mbooleanpublishsubject.onnext(true);     thread.sleep(1000);     mbooleanpublishsubject.onnext(true);     thread.sleep(2000); } 

and output is

on value emitted 1454063289770 on value emitted 2 1454063289770 on value emitted 2 1454063289779 on value emitted 3 1454063289780 done 1454063289780 on value emitted 3 1454063289780 

i can't figure out why on value emitted 2 , on value emitted 3 appears in log twice , why debounce delay doesn't work. can please help?

discussed here

to resolve duplicate items in log issue should use doonnext instead of dooneach, such dooneach include oncompleted events

take(1) completes observable immediately, why debounce doesn't work. delay should used instead of

mbooleanpublishsubject.asobservable()         .doonnext(__ -> system.out.println("on value emitted " + system.currenttimemillis()))         .take(1)         .doonnext(__ -> system.out.println("on value emitted 2 " + system.currenttimemillis()))         .delay(1, timeunit.seconds)         .doonnext(__ -> system.out.println("on value emitted 3 " + system.currenttimemillis()))         .subscribe(__ -> system.out.println("done " + system.currenttimemillis())); 

Comments