reactive programming - How hook observable starting on delayed subscription in rxjava -
usability: when user press button, search starts after 3000 msec. when search starts, progress bar should shown.
i have delayed subscription:
observable<searchresult> delayedsearch = search .delaysubscription(3000, timeunit.milliseconds) //not working .doonsubscribe(() -> log(should appear progress bar)) delayedsearch.subscribe(result -> log(should disappear progress bar)); problem: can't hook start observable's execution.
how best way solve problem? or maybe solution?
i found solution.
create showprogress observable:
observable showprogress = observable.create(subscriber -> { log("showprogress") subscriber.onnext(null); subscriber.oncompleted(); }).subscribeon(androidschedulers.mainthread()); and add before searching:
observable<searchresult> searchwithprogress = showprogress.flatmap((func1) o -> search); so can use this:
observable<searchresult> delayedsearch = searchwithprogress.delaysubscription(3000, timeunit.milliseconds); delayedsearch.subscribe(result -> log(hideprogress);
Comments
Post a Comment