reactive-programming

RxJs: How to loop based on state of the observable?

こ雲淡風輕ζ 提交于 2019-11-29 09:36:58
I'm trying to get RxJs to loop over an Observable in my stream until it is in a certain state, then have the stream continue. Specifically I'm converting a synchronous do/while loop to RxJs, but I assume the same answer could be used for a for or while loop as well. I thought I could use doWhile() for this, but it seems like the condition function does not have access to the item in the stream, which seems to defeat the purpose to me. I'm not completely sure what the correct reactive terminology is for what I want, but here is an example of what I am going for: var source = new Rx.Observable

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

删除回忆录丶 提交于 2019-11-29 08:36:43
问题 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. 回答1: Definition My (own) favorite definition: A

RxJava — Terminating Infinite Streams

白昼怎懂夜的黑 提交于 2019-11-29 08:14:43
问题 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

Rxjs - How can I extract multiple values inside an array and feed them back to the observable stream synchronously

最后都变了- 提交于 2019-11-29 07:56:10
I have created a Rx.Observable from a stream of events: Rx.Observable.fromEvent(recognizeStream, 'data') In which every data event looks like this: { error: null, alternatives: [result1, result2, result3] } I want to pluck every value inside the array of alternatives and merge those into the stream. What operators do I have to look at? As far as I know the flatMap and concatMap could do the job but I don't get the idea from their example. Can somebody explain which operator i should use and provide me with an example? The family of xxxMap() operators all deal with higher-order Observables.

How to constraint concurrency the right way in Rx.NET

霸气de小男生 提交于 2019-11-29 07:14:48
Please, observe the following code snippet: var result = await GetSource(1000).SelectMany(s => getResultAsync(s).ToObservable()).ToList(); The problem with this code is that getResultAsync runs concurrently in an unconstrained fashion. Which could be not what we want in certain cases. Suppose I want to restrict its concurrency to at most 10 concurrent invocations. What is the Rx.NET way to do it? I am enclosing a simple console application that demonstrates the subject and my lame solution of the described problem. There is a bit extra code, like the Stats class and the artificial random

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

狂风中的少年 提交于 2019-11-29 06:22:33
问题 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

How to get String from Mono<String> in reactive java

折月煮酒 提交于 2019-11-29 04:48:39
I have a method which accepts Mono as a param. All I want is to get the actual String from it. Googled but didn't find answer except calling block() over Mono object but it will make a blocking call so want to avoid using block(). Please suggest other way if possible. The reason why I need this String is because inside this method I need to call another method say print() with the actual String value. I understand this is easy but I am new to reactive programming. Code: public String getValue(Mono<String> monoString) { // How to get actual String from param monoString //and call print(String)

Can reactive-banana handle cycles in the network?

本小妞迷上赌 提交于 2019-11-29 03:29:10
We have code like this: guiState :: Discrete GuiState guiState = stepperD (GuiState []) $ union (mkGuiState <$> changes model) evtAutoLayout evtAutoLayout :: Event GuiState evtAutoLayout = fmap fromJust . filterE isJust . fmap autoLayout $ changes guiState You can see that evtAutoLayout feeds into guiState which feeds into evtAutoLayout--so there is a cycle there. This is deliberate. Auto layout adjusts the gui state until it reaches an equilibrium and then it returns Nothing and so it should stop the loop. A new model change can kick it off again, of course. When we put this together, though,

How do I implement polling using Observables?

你离开我真会死。 提交于 2019-11-29 02:07:33
I have a parametrized rest call that should be executed every five seconds with different params: Observable<TResult> restCall = api.method1(param1); I need to create an Observable<TResult> which will poll the restCall every 5 seconds with different values for param1. If the api call fails I need to get an error and make the next call in 5 seconds. The interval between calls should be measured only when restCall is finished (success/error). I'm currently using RxJava, but a .NET example would also be good. James World Introduction First, an admission, I'm a .NET guy, and I know this approach

Spring 5 WebClient using ssl

。_饼干妹妹 提交于 2019-11-29 02:02:24
I'm trying to find examples of WebClient use. My goal is to use Spring 5 WebClient to query a REST service using https and self signed certificate Any example ? See example of use insecure TrustManagerFactory that trusts all X.509 certificates (including self-signed) without any verification. The important note from documentation: Never use this TrustManagerFactory in production. It is purely for testing purposes, and thus it is very insecure. @Bean public WebClient createWebClient() throws SSLException { SslContext sslContext = SslContextBuilder .forClient() .trustManager