reactive-programming

How To Do Recursive Observable Call in RxJava?

故事扮演 提交于 2019-11-30 13:44:38
I am quite new to RxJava (and Reactive paradigm in general), so please bear with me. Suppose I have this News and this nested Comment data structure: public class News { public int id; public int[] commentIds; //only top level comments public News(int id, int[] commentIds) { this.id = id; this.commentIds = commentIds; } } public class Comment { public int id; public int parentId; //ID of parent News or parent comment public int[] childIds; public Comment(int id, int parentId, int[] childIds) { this.id = id; this.parentId = parentId; this.childIds = childIds; } } and suppose I have this API

Rx back off and retry

六月ゝ 毕业季﹏ 提交于 2019-11-30 13:02:16
This is based on the code presented in this SO : Write an Rx "RetryAfter" extension method I am using the code by Markus Olsson (evaluation only at the moment), and before anyone asks I have tried to get hold of Markus on Github, but that is blocked where I work, so I felt the only thing I could do was ask here at SO. Sorry about that, if this sits badly with any one. So I am using the following code, in a small demo which is this: class Attempt1 { private static bool shouldThrow = true; static void Main(string[] args) { Generate().RetryWithBackoffStrategy(3, MyRxExtensions.ExponentialBackoff,

How to get data from observable in angular2

*爱你&永不变心* 提交于 2019-11-30 11:18:16
问题 I am trying to print the result of http call in Angular using rxjs Consider the following code import { Component, Injectable, OnInit } from '@angular/core'; import { Http, HTTP_PROVIDERS } from '@angular/http'; import 'rxjs/Rx'; @Injectable() class myHTTPService { constructor(private http: Http) {} configEndPoint: string = '/my_url/get_config'; getConfig() { return this.http .get(this.configEndPoint) .map(res => res.json()); } } @Component({ selector: 'my-app', templateUrl: './myTemplate',

RxJava — Terminating Infinite Streams

本小妞迷上赌 提交于 2019-11-30 07:07:49
I am exploring reactive programming and RxJava. It is fun, but I am stuck on a problem for which I cannot find an answer. My basic question: what is a reactive-appropriate way to terminate an otherwise infinitely-running Observable? I also welcome critiques and reactive best practices regarding my code. As an exercise, I am writing a log file tail utility. The stream of lines in the log file is represented by an Observable<String> . To get the BufferedReader to continue reading text that is added to the file, I ignore the usual reader.readLine() == null termination check and instead interpret

Terminology: What is a “glitch” in Functional Reactive Programming / RX?

末鹿安然 提交于 2019-11-30 06:50:18
What is the definition of a "glitch" in the context of Functional Reactive Programming? I know that in some FRP frameworks "glitches" can occur while in others not. For example RX is not glitch free while ReactFX is glitch free [ 1 ]. Could someone give a very simple example demonstrating how and when glitches can occur when using RX and show on the same example how and why the corresponding ReactFX solution is glitch free. Thanks for reading. Definition My (own) favorite definition: A glitch is a temporary inconsistency in the observable state. Definition from Scala.Rx : In the context of FRP

How can I make this rxjava zip to run in parallel?

房东的猫 提交于 2019-11-30 06:47:16
问题 I have a sleep method for simulating a long running process. private void sleep() { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } Then I have a method returns an Observable containing a list of 2 strings that is given in the parameters. It calls the sleep before return the strings back. private Observable<List<String>> getStrings(final String str1, final String str2) { return Observable.fromCallable(new Callable<List<String>>() { @Override public List

RxJava- Is cache() the same as replay()?

丶灬走出姿态 提交于 2019-11-30 06:41:23
I was wondering if there was a cache() operator that could cache x number of emissions but also expire them after a specified time interval (e.g. 1 minute). I was looking for something like... Observable<ImmutableList<MyType>> cachedList = otherObservable .cache(1, 1, TimeUnit.MINUTES); This would cache one item but would expire and clear the cache after a minute. I did some research and found the replay operator. It seemed like it would fulfill this need but I have some questions. Why is it hot and needs to be connected? Does this make it different than the cache() operator? I know the cache(

RxJs: lossy form of zip operator

别来无恙 提交于 2019-11-30 04:38:51
问题 Consider using the zip operator to zip together two infinite Observables, one of which emits items twice as frequently as the other. The current implementation is loss-less, i.e. if I keep these Observables emitting for an hour and then I switch between their emitting rates, the first Observable will eventually catch up with the other. This will cause memory explosion at some point as the buffer grows larger and larger. The same will happen if first observable will emit items for several

Android Pros & Cons: Event Bus and RxJava

馋奶兔 提交于 2019-11-30 03:39:01
I have been using Event Bus in my apps (i.e: greenrobot/EventBus). But I find some disadvantages in using Event Bus: Chaining tasks execution is difficult A lot of classes to represent events Less clear code (well, it's still possible to trace, but not as clear) I have been researching for new techniques to deal with this problem. And I read quite a bit about RxJava and wonder if it could be a solution. So my questions about RxJava (based on what I have read recently): Could RxJava observer be registered at any time? So not just when creating the Observable. With EventBus this is possible, I

Using Reactive extension (Rx) for MSMQ message receive using async pattern (queue.BeginReceive,queue.EndReceive)

别说谁变了你拦得住时间么 提交于 2019-11-30 03:20:28
问题 I have been using Rx for a while now for Events on my projects and dedicatedly for Socket programming and the good part is its doing well. Managing my code, performance advantage and much better to execute and interpret. Lately I have to modify my project's process flow where i need to dump all the incoming data (from socket operations) into queues ( using MSMQ implementation as decided for queueing ). As MSMQ provides async call for dequeing messages from the queue (but in an wierd pattern).