reactive-programming

How to constraint concurrency the right way in Rx.NET

自作多情 提交于 2019-11-27 22:28:30
问题 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

IConnectableObservables in Rx

杀马特。学长 韩版系。学妹 提交于 2019-11-27 20:19:34
问题 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. 回答1: 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

Can reactive-banana handle cycles in the network?

妖精的绣舞 提交于 2019-11-27 17:36:18
问题 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

Combine a list of Observables and wait until all completed

末鹿安然 提交于 2019-11-27 16:55:33
TL;DR How to convert Task.whenAll(List<Task>) into RxJava ? My existing code uses Bolts to build up a list of asynchronous tasks and waits until all of those tasks finish before performing other steps. Essentially, it builds up a List<Task> and returns a single Task which is marked as completed when all tasks in the list complete, as per the example on the Bolts site . I'm looking to replace Bolts with RxJava and I'm assuming this method of building up a list of async tasks (size not known in advance) and wrapping them all into a single Observable is possible, but I don't know how. I've tried

RxJava Combine Sequence Of Requests

自闭症网瘾萝莉.ら 提交于 2019-11-27 14:43:07
问题 The Problem I have two Apis. Api 1 gives me a List of Items and Api 2 gives me more detailed Information for each of the items I got from Api 1. The way I solved it so far results in bad Performance. The Question Efficent and fast solution to this Problem with the help of Retrofit and RxJava. My Approach At the Moment my Solution Looks like this: Step 1: Retrofit executes Single<ArrayList<Information>> from Api 1. Step 2: I iterate through this Items and make a request for each to Api 2. Step

Reordering events with Reactive Extensions

烈酒焚心 提交于 2019-11-27 13:27:41
问题 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();

Create PDF file from HTML text React

纵然是瞬间 提交于 2019-11-27 13:14:59
问题 I am beginner in react-redux. I trying create a function like exporting a html text to pdf with Javascript and it works with html, but when I apply it to react component, it doesn't work. This is my code: import React from 'react'; class App extends React.Component { constructor(props){ super(props); this.pdfToHTML=this.pdfToHTML.bind(this); } pdfToHTML(){ var pdf = new jsPDF('p', 'pt', 'letter'); var source = $('#HTMLtoPDF')[0]; var specialElementHandlers = { '#bypassme': function(element,

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

坚强是说给别人听的谎言 提交于 2019-11-27 10:46:31
问题 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

Correct way of throwing exceptions with Reactor

杀马特。学长 韩版系。学妹 提交于 2019-11-27 09:52:48
问题 I'm new to project Reactor and reactive programming in general. I'm currently working on a piece of code similar to this: Mono.just(userId) .map(repo::findById) .map(user-> { if(user == null){ throw new UserNotFoundException(); } return user; }) // ... other mappings This example is probably silly and there are surely better ways of implementing this case, but the point is: Is it wrong to use a throw new exception in a map block or should I replace this with a return Mono.error(new

Paginate Observable results without recursion - RxJava

你。 提交于 2019-11-27 09:09:48
I've got a pretty standard API pagination problem which you can handle with some simple recursion. Here's a fabricated example: public Observable<List<Result>> scan() { return scanPage(Optional.empty(), ImmutableList.of()); } private Observable<?> scanPage(Optional<KEY> startKey, List<Result> results) { return this.scanner.scan(startKey, LIMIT) .flatMap(page -> { if (!page.getLastKey().isPresent()) { return Observable.just(results); } return scanPage(page.getLastKey(), ImmutableList.<Result>builder() .addAll(results) .addAll(page.getResults()) .build() ); }); } But this can obviously create a