reactive-programming

“Buffer until quiet” behavior from Reactive?

萝らか妹 提交于 2019-12-10 21:08:07
问题 My problem is sort of like the one the Nagle algorithm was created to solve, but not exactly. What I'd like is to buffer the OnNext notifications from an IObservable<T> into a sequence of IObservable<IList<T>> s like so: When the first T notification arrives, add it to a buffer and start a countdown If another T notification arrives before the countdown expires, add it to the buffer and restart the countdown Once the countdown expires (i.e. the producer has been silent for some length of time

Making a typing timer in RxJS; Tracking time spent typing

南笙酒味 提交于 2019-12-10 18:08:37
问题 This question is an extension of my previous question that you can find here: How to use RxJS to display a "user is typing" indicator? After having successfully been able to track whether or not the user was typing, I needed to be able to use that particular state as a trigger for a clock. The logic is simple, essentially I want a clock to be run when the user is typing. But when the user stops typing, I need the clock to pause. When the user starts typing again, the clock should continue to

Spring Integration 5.0 + Project Reactor: controlling threads

蹲街弑〆低调 提交于 2019-12-10 18:08:21
问题 Followup question for https://stackoverflow.com/a/47136941/1776585 I can't make my integration handler to run in parallel threads while using Flux + split() + FluxMessageChannel . Consider the following snippet: // ... .handle(message -> Flux.range(0, 10) .doOnNext(i -> LOG.info("> " + i)) .subscribeOn(Schedulers.parallel())) .split() .channel(new FluxMessageChannel()) .handle(message -> LOG.info(" -> " + message.getPayload()))) // ... All logs are output in one thread: [ parallel-1] d.a

Reactive Extensions SelectMany and Concat

ぐ巨炮叔叔 提交于 2019-12-10 17:51:44
问题 I understand that the behaviour of SelectMany is to effectively merge the results of each value produced into a single stream so the ordering in nondeterministic. How do I do something similar to concatAll in RxJs in C#. var obs = Observable.Range (1, 10).SelectMany (x => { return Observable.Interval (TimeSpan.FromSeconds(10 - x)).Take (3); }).Concat(); This is effectively what I want to do, Given a Range, Wait a bit for each then concat in the order that they started in. Obviously this is a

Reactive WebSockets with Spring 5 - how to get initial message

笑着哭i 提交于 2019-12-10 15:42:05
问题 I followed that tutorial (specifically the part with the Browser WebSocket Client): http://www.baeldung.com/spring-5-reactive-websockets Everything works fine. I would like to go a step further and having my handler behave according to a parameter sent from the client side. On connection the client is sending a message ("event-me-from-browser"): var clientWebSocket = new WebSocket("ws://localhost:8080/event-emitter"); clientWebSocket.onopen = function() { console.log("clientWebSocket.onopen",

RxJava - How to take the first element of a list and return it as Observable

北慕城南 提交于 2019-12-10 15:28:26
问题 Let's take this observable: Observable<List<UserProfile>> findUser =service.getUserProfiles() How can I transform it so it returns the first element as an Observable (and not an Observable list just containing the first element). I tried first() and takeFirst() but it still returns a list. 回答1: Map it! Observable<List<UserProfile>> findUser = service.getUserProfiles(); Observable<UserProfile> firstUser = findUser .filter(list -> !list.isEmpty()) .map(list -> list.get(0)); 回答2: Without see

Reactive Extensions (Rx) - sample with last known value when no value is present in interval

守給你的承諾、 提交于 2019-12-10 14:34:24
问题 I have an observable stream that produces values at inconsistent intervals like this: ------1---2------3----------------4--------------5--- And I would like to sample this but without any empty samples once the a value has been produced: ------1---2------3----------------4--------------5----- ----_----1----2----3----3----3----4----4----4----5----5 I obviously thought Replay().RefCount() could be used here to provide the last known value to Sample() but as it doesn't re-subscribe to the source

Wait for multiple async calls to finish in RxJava

青春壹個敷衍的年華 提交于 2019-12-10 14:26:57
问题 My scenario is quite simple, but I don't seem to able to find it anywhere. I have a set of elements that I want to iterate through, for each one call an async function, and then wait for all of them to finish (which again happens in an asynchronous fashion, implemented in the logic of the function). I'm relatively new to RxJava and used to do this easily in NodeJS by passing callback to the function and wait at the end. Here's the pseudocode of what I need (the iterator for elements does not

Using RxJava for email login validation, an observable is emitting twice

人盡茶涼 提交于 2019-12-10 14:14:31
问题 I'm making a simple login form (email and password) to try and bolster my reactive programming skillset. I'm having some trouble getting the email field validation to work the way I want it. Here's my code: final Observable<CharSequence> email = RxTextView.textChanges(emailView); Observable<Boolean> emailIsValid = email.map(new Func1<CharSequence, Boolean>() { @Override public Boolean call(CharSequence charSequence) { Log.d("asdf", "emailIsValid call: " + charSequence); return Pattern.matches

combineLatest emit only when one of the streams changes

浪尽此生 提交于 2019-12-10 13:36:25
问题 I have a stream with frequent values and one with slower ones. I want to combine them, but only emit a value when the slower one emits. So combineLatest doesn't work. Like so: a1 a2 b1 (a2,b1) a3 a4 a5 b2 (a5,b2) Currently I'm doing it like follows, is there a cleaner way? withLatest[A,B](fast : Observable[A], slow : Observable[B]): Observable[(A,B)] = Observable({ o => var last : A fast.subscribe({a => last = a}) slow.subscribe({b => o.onNext((last,b))}) }) edit : This operator is now in Rx