reactive-programming

Observable.Retry doesn't work as expected

南笙酒味 提交于 2019-12-08 06:35:56
问题 I have a sequence of numbers that are processed using an async method. I'm simulating a remote service call that may fail . In case of failure, I would like to retry until the call successes. The problem is that with the code I'm trying, every time an exception is thrown in the async method, the sequence seems to hang forever . You can test it with this simple code snippet (it's tested in LINQPad) Random rnd = new Random(); void Main() { var numbers = Enumerable.Range(1, 10).ToObservable();

Resubscribe to takeUntil/skipUntil

馋奶兔 提交于 2019-12-08 06:31:44
问题 The following code defines behavior i want (it works). Emmition of mousemove event occur only when mouse down. Rx.Observable.fromEvent(window,"mouseup") .subscribe( () => { if(subscription) subscription.dispose(); } ) Rx.Observable.fromEvent(window,"mousedown") .subscribe( () => { subscription = Rx.Observable.fromEvent(window,"mousemove") .subscribe( (event) => console.log(event) ) } ) I want to rewrite it using takeUntil/skipUntil operators. But this fails: let fs = [ (e) => console.log(e),

Why does my RxJava Observable emit only to the first consumer?

♀尐吖头ヾ 提交于 2019-12-08 05:55:33
问题 Can someone explain why the below test fails? public class ObservableTest { @Test public void badObservableUsedTwiceDoesNotEmitToSecondConsumer() { // Any simpler observable makes the test pass Observable<Integer> badObservable = Observable.just(1) .zipWith(Observable.just(2), (one, two) -> Observable.just(3)) .flatMap(observable -> observable); ObservableCalculator calc1 = new ObservableCalculator(badObservable); ObservableCalculator calc2 = new ObservableCalculator(badObservable); //

Combining Observables when both change simultaneously

左心房为你撑大大i 提交于 2019-12-08 05:44:32
问题 I am trying to integrate ReactiveX into my GUI using RxPY. This is a general ReactiveX question. Say I have a visualization that depends on multiple Observable streams using combine_latest(stream1, stream2, plot_function) . This works great when one Observable changes, like when the user modifies a value; the visualization updates using the new values. However, sometimes both Observables are updated simultaneously, like when the user loads data for both streams from a single file. Technically

Spring 5 Reactive - WebExceptionHandler is not getting called

爷,独闯天下 提交于 2019-12-08 05:43:48
问题 I have tried all 3 solutions suggested in what is the right way to handle errors in spring-webflux, but WebExceptionHandler is not getting called. I am using Spring Boot 2.0.0.M7 . Github repo here @Configuration class RoutesConfiguration { @Autowired private lateinit var testService: TestService @Autowired private lateinit var globalErrorHandler: GlobalErrorHandler @Bean fun routerFunction(): RouterFunction<ServerResponse> = router { ("/test").nest { GET("/") { ServerResponse.ok().body

RxJava: how to code something like doOnEmpty?

走远了吗. 提交于 2019-12-08 03:28:03
问题 I am using several filters on my Observable and I would like to report cases at the end of filtering when the result was empty. I cannot do it at the end of processing because this observable is supposed to be concatenated with another one: Observable.just(1, 2, 3) .concatWith( Observable.just(2, 4, 6) .filter(value -> ((value % 2) != 0)) // report if empty ) 回答1: You can use Transformers.doOnEmpty from rxjava-extras which is on Maven Central: source.compose(Transformers.doOnEmpty(action))

Setting up data refreshing in Shiny app connected to PostgreSQL

这一生的挚爱 提交于 2019-12-07 19:46:31
问题 I've looked at this and this thread and a few others but haven't been able to figure out my solution. I have built a dashboard using R and Shiny, and said dashboard pulls in data from a Postgres db using the RPostgreSQL package. Right now, the code for all the data pulling and analysis is done outside of the shinyServer function, and only the displaying part (the output and render functions) is in the shinyServer portion. I'd like to set it up so that the dashboard data is periodically

RxJava: How to express doOnFirst()?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 15:48:27
问题 I am using RxJava and I have an Observable with multiple items inside. What I would like to do is run function A on the first item, function B on all of them and function C when the Observable is completed: -----1-----2-----3-----|--> | | | | run A | | | | | | | run B run B run B | | run C is there a clever way of expressing this with lambda functions? I have the following solution already, but it looks ugly and I suspect that there is a better way to do this: observable.subscribe( new

Continue the subscription after error

守給你的承諾、 提交于 2019-12-07 15:31:02
问题 I have a code where for each of the ids I am making an ajax request and processing them as results come in. Here is a simple replica of my actual code and jsfiddle: var ids = [1,2,3,4,5,6]; var ids$ = (id) => { return Observable.of(id); }; var loadIds$ = (id) => { if(id == 4) return xhr('/echo/jsoneee/', {id: id}); return xhr('/echo/json/', {id: id}); }; Observable.from(ids) .concatMap(id => Observable.forkJoin(ids$(id), loadIds$(id))) .catch((err, caught) => { //get the id for which loadIds

do Operators instead of a whole Subscriber

北城余情 提交于 2019-12-07 14:31:45
问题 It's quite appealing to use Action (s) instead of a whole Subscriber when you only need OnNext() merely because it's more readable. But of course, errors happen and if you only use Action1 you'll get an Exception in your app. do operators can be of help here. I'm only concerned these two approaches are fully the same, please confirm or disconfirm. Any pitfalls? The first approach: Observable .just(readFromDatabase()) .doOnError(new Action1<Throwable>() { @Override public void call(Throwable