reactive-programming

What Am I Missing About Reactive Extension Timers?

天涯浪子 提交于 2019-12-08 10:04:48
问题 I have this: watchers .ToObservable() // needs to be observable .SelectMany(watcher => // working on each watcher Observable // create a timer for the watcher .Timer(watcher.StartTime, TimeSpan.FromHours(watcher.Interval)) .SelectMany(Observable.FromAsync( async () => new { watcher, result = await CheckFolder(watcher.Path) }))) .Subscribe(x => Console.WriteLine(string.Format("Watcher: {0}\tResult: {1}\tTime: {2}", x.watcher.Name, x.result, DateTimeOffset.Now))); // tell everyone what happened

How to continue the stream with error in Rx?

余生颓废 提交于 2019-12-08 10:04:29
问题 I am developing an Android app using Kotlin, RxJava, Retrofit. I want to send Http Request to the server. PUT - update option of job POST - run the job After the first request success, then I send a second request. So I used concatMap. val updateJob = restService.updateJob(token, job.id, options) // PUT val runJob = restService.runJob(token, job.id) // POST updateJob.concatMap { runJob } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ job -> Log.d(TAG,

How to merge several objects into a single one after execute the groupBy operation?

家住魔仙堡 提交于 2019-12-08 09:39:01
问题 I have the class below that I've created to illustrate my doubt. After doing the initial transformations on my flowable I have: UserScoreTO{id=1, name='john', score=4} UserScoreTO{id=1, name='john', score=5} UserScoreTO{id=1, name='john', score=1} UserScoreTO{id=2, name='paul', score=4} UserScoreTO{id=2, name='paul', score=2} UserScoreTO{id=3, name='mark', score=1} UserScoreTO{id=3, name='mark', score=7} I want to combine UserScoreTO objects with the same id into a Flowable that emits one

Can a Subscriber act as a Publisher?

蓝咒 提交于 2019-12-08 09:12:23
In terms of Reactive Streams, there is a Publisher and it could have as many Subscribers. But suppose, a subscriber gets a message from Publisher. Now this Subscriber(say Subs1) changes/modifies the message and passes it to some other Subscriber(say Subs2), which consumes the modified message. So can this Subs1 subscriber can act as a Publisher which can pass on message to new Subs2 subscriber? I am not sure if it possible or not, but the scenario is possible i think. If its possible, please suggest a possible way to do this. If we want to transform incoming message and pass it further to the

RxJava alternative of group by in sql

你说的曾经没有我的故事 提交于 2019-12-08 09:07:28
问题 I have a list of Student : Observable<Student> source = Observable.fromIterable(getStudentList()); I would like to group them by postal code, along with how many times they appear, but the problem is that I use java 7 how to do this? 回答1: Use groupBy , flatMap and count on the groups themselves: source.groupBy(s -> s.postalCode) .flatMapSingle(g -> g.count() .map(v -> g.getKey() + ": " + v)) ; Without lambdas it looks more ugly though: source.groupBy(new Function<Student, String>() {

Can a Subscriber act as a Publisher?

核能气质少年 提交于 2019-12-08 08:47:19
问题 In terms of Reactive Streams, there is a Publisher and it could have as many Subscribers. But suppose, a subscriber gets a message from Publisher. Now this Subscriber(say Subs1) changes/modifies the message and passes it to some other Subscriber(say Subs2), which consumes the modified message. So can this Subs1 subscriber can act as a Publisher which can pass on message to new Subs2 subscriber? I am not sure if it possible or not, but the scenario is possible i think. If its possible, please

RX - Zip outputs an unexpected result

不打扰是莪最后的温柔 提交于 2019-12-08 08:47:07
问题 Please help me understand a phenomenon : Why is X NOT equal to index in the Observable's items ? Building blocks for example : public class EcgSample { public EcgSample(int y) { Y = y; } public int X { get; set; } public int Y { get; set; } } private void Print(Tuple<EcgSample, int> s) { Debug.WriteLine("X : {0} , Y : {1} , Index : {2}", s.Item1.X, s.Item1.Y, s.Item2); } private List<EcgSample> CreateSamples() { var testSamples = new List<EcgSample>(); for (short i = 0; i < 1400; i++) {

Spring webflux WebClient logs 'Connection reset by peer'

冷暖自知 提交于 2019-12-08 07:51:16
问题 I have this following code which uses WebClient to make HTTP calls. webClient.post() .uri("/users/track") .body(BodyInserters.fromObject(getUserTrackPayload(selection, customAttribute, partyId).toString())) .header(CONTENT_TYPE, APPLICATION_JSON) .retrieve() .onStatus(httpStatus -> !CREATED.equals(httpStatus), response -> response.bodyToMono(String.class) .flatMap(body -> buildErrorMessage(response.statusCode().value(), body, partyId, customAttribute) .flatMap(e -> Mono.error(new MyException

RxJava: how to code something like doOnEmpty?

此生再无相见时 提交于 2019-12-08 07:05:36
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 ) You can use Transformers.doOnEmpty from rxjava-extras which is on Maven Central: source.compose(Transformers.doOnEmpty(action)) You might use this solution if you cared about efficiency (allocations/performance) but otherwise use

How to continue streaming items after error in RxJava?

陌路散爱 提交于 2019-12-08 06:37:59
问题 I'm RxJava newbie, and I've got following problem. Say I have sequence of items and on of items propagates error, I want to ignore it and to continue processing other items. I have following snippet: Observable.from(Arrays.asList("1", "2", "3")) .map(x -> { if (x.equals("2")) { throw new NullPointerException(); } return x + "-"; }) .onExceptionResumeNext(Observable.empty()) .subscribe(System.out::println); I'm getting: 1- But I want to get: 1- , 3- How can I do that? 回答1: the trick is to wrap