reactive-programming

Database polling with Reactive Extensions

允我心安 提交于 2019-11-29 01:31:52
问题 I have to query a database in a timely fashion to know the state of a legacy system. I've thought of wrapping the query around an Observable , but I don't know the correct way to do it. Basically, it will be the same query every 5 seconds. But I'm afraid I will have to face these problems: What if the execution of the query takes 10 seconds? I don't want to execute any new query if the previous is still being processed. Also, there should be a timeout. If the current query doesn't execute

Chain two retrofit observables w/ RxJava

ぃ、小莉子 提交于 2019-11-28 23:02:23
问题 I want to execute 2 network calls one after another. Both network calls return Observable. Second call uses data from successful result of the first call, method in successful result of second call uses data from both successful result of the first and of the second call. Also i should be able to handle both onError "events" differently. How can i achieve this avoiding callback hell like in example below: API().auth(email, password) .subscribeOn(Schedulers.newThread()) .observeOn

Reordering events with Reactive Extensions

被刻印的时光 ゝ 提交于 2019-11-28 20:51:29
I'm trying to reorder events arriving unordered on different threads. Is it possible to create a reactive extension query that matches these marble diagrams: s1 1 2 3 4 s2 1 3 2 4 result 1 2 3 4 and... s1 1 2 3 4 s2 4 3 2 1 result 1234 That is: Only publish results in version number order. The closest I have got is using a Join to open a window each time s1 ticks and only close it when s2 arrives with the same number. Like this: var publishedEvents = events.Publish().RefCount(); publishedEvents.Join( publishedEvents.Scan(0, (i, o) => i + 1), expectedVersion => publishedEvents.Any(@event =>

Mono vs Flux in Reactive Stream

那年仲夏 提交于 2019-11-28 19:50:34
问题 As per the documentation: Flux is a stream which can emit 0..N elements: Flux<String> fl = Flux.just("a", "b", "c"); Mono is a stream of 0..1 elements: Mono<String> mn = Mono.just("hello"); And as both are the implementations of the Publisher interface in the reactive stream. Can't we use only Flux in most of the cases as it also can emit 0..1, thus satisfying the conditions of a Mono? Or there are some specific conditions when only Mono needs to be used and Flux can not handle the operations

Search on TextChanged with Reactive Extensions

牧云@^-^@ 提交于 2019-11-28 18:57:27
I was trying to implement instant search on a database table with 10000+ records. The search starts when the text inside the search text box changes, when the search box becomes empty I want to call a different method that loads all the data. Also if the user changes the search string while results for another search are being loaded, then the loading of the those results should stop in favor of the new search. I implemented it like the following code, but I was wondering if there is a better or cleaner way to do it using Rx (Reactive Extension) operators, I feel that creating a second

IConnectableObservables in Rx

断了今生、忘了曾经 提交于 2019-11-28 18:11:22
Can someone explain the differences between an Observable and a ConnectableObservable? The Rx Extensions documentation is very sparse and I don't understand in what cases the ConnectableObservable is useful. This class is used in the Replay/Prune methods. Short answer: IConnectableObservable represents a pending hot observable that can be shared with multiple subscribers. Calling IConnectableObservable.Connect() causes the change to hot (subscribes to the cold source observable) Long answer: A cold observable (like Observable.Range ) replays the sequence for each subscriber. It's analagous to

Spring webflux and reading from database

二次信任 提交于 2019-11-28 17:54:50
Spring 5 introduces the reactive programming style for rest APIs with webflux . I'm fairly new to it myself and was wondering wether wrapping synchronous calls to a database into Flux or Mono makes sense preformence-wise? If yes, is this the way to do it: @RestController public class HomeController { private MeasurementRepository repository; public HomeController(MeasurementRepository repository){ this.repository = repository; } @GetMapping(value = "/v1/measurements") public Flux<Measurement> getMeasurements() { return Flux.fromIterable(repository.findByFromDateGreaterThanEqual(new Date

RxJava 2.x: Should I use Flowable or Single/Completable?

[亡魂溺海] 提交于 2019-11-28 17:49:51
I'm developing an Android app using Clean Architecture and I'm migrating it to RxJava 2.x. I have to make some network requests to a soap service, so I defined the api interface in the domain module: public interface SiginterApi { Observable<User> login(String user, String password); ... Observable<List<Campaign>> getCampaigns(List<Long> campaignIds); } I've read that a network request should be made with " Flowable ", because of the backpressure management since it's a 'cold observable'. On the other hand, I know the result of the request will be success (with the response) or error, so I don

Backpressure mechanism in Spring Web-Flux

孤街醉人 提交于 2019-11-28 16:20:15
问题 I'm a starter in Spring Web-Flux . I wrote a controller as follows: @RestController public class FirstController { @GetMapping("/first") public Mono<String> getAllTweets() { return Mono.just("I am First Mono") } } I know one of the reactive benefits is Backpressure , and it can balance the request or the response rate. I want to realize how to have backpressure mechanism in Spring Web-Flux . 回答1: Backpressure in WebFlux In order to understand how Backpressure works in the current

What is LINQ to events a.k.a RX Framework?

人走茶凉 提交于 2019-11-28 16:18:07
问题 What is LINQ to events a.k.a RX Framework aka the Reactive Extensions in .NET 4.0 (but also available as backported versions)? In other words, what is all the stuff in System.Reactive.dll for? 回答1: .NET Rx team (this is not an official name) found that any push sequence (events, callbacks) can be viewed as a pull sequence (as we normally do while accessing enumerables) as well – or they are Dual in nature. In short observer/observable pattern is the dual of enumeration pattern. So what is