reactive-programming

How to convert rxJava2's Observable to Completable?

試著忘記壹切 提交于 2019-12-04 15:33:41
问题 I have Observable stream, and I want to convert it to Completable, how I could do that? 回答1: The fluent way is to use Observable.ignoreElements() . Observable.just(1, 2, 3) .ignoreElements() Convert it back via toObservable if needed. 回答2: You can do something like below. Observable<Integer> observable = Observable.just(1, 2, 3); Completable completable = Completable.fromObservable(observable); Like on an Observable, you will have to subscribe to the completable to start the asynchronous

Asynchronous RestAPIs with RxJava/Jersey2. Threading questions?

徘徊边缘 提交于 2019-12-04 14:43:25
问题 We are in the process of prototyping a REST API using reactive programming. As shown in the diagram, we keep 3 layers same as we used in our previouse sync API designs ; http://oi59.tinypic.com/339hhki.jpg API Layer implemented using Jersey2 which will process request/deserialize JSON and handover to Service Layer. Service Layer which implements the business-logic.Implemented using reactive programming (RxJava) Dao Layer which is used for persistence operations by Service Layer.Since we use

Rx how to group by a key a complex object and later do SelectMany without “stopping” the stream?

一个人想着一个人 提交于 2019-12-04 12:07:23
This is related to my other question here . James World presented a solution as follows: // idStream is an IObservable<int> of the input stream of IDs // alarmInterval is a Func<int, TimeSpan> that gets the interval given the ID var idAlarmStream = idStream .GroupByUntil(key => key, grp => grp.Throttle(alarmInterval(grp.Key))) .SelectMany(grp => grp.IgnoreElements().Concat(Observable.Return(grp.Key))); <edit 2: Question: How do I start the timers immediately without waiting for the first events to arrive? That's the root problem in my question, I guess. For that end, I planned on sending off

MeteorJS - Watch for server variable change and update the template value

≡放荡痞女 提交于 2019-12-04 11:35:48
I have a doubt. Not sure if it's possible and didn't find a clear answer about it. Is it possible to add a "watcher" to a server variable so when the value changes, I can update the view (client side) ? Let say I have a var counter = 0 and a Timeout function which updates the counter variable every minute. I want to update a <span>{{counter}}</span> in the client side. I would need to add a "watcher" to this server variable and make it reactive. Thanks in advance! The correct way to do this is to make a collection and store that variable in the collection (even if this means you have a

RxJava - When and why to use Observable.share()

我的未来我决定 提交于 2019-12-04 10:52:52
问题 I've seen patters like this: Observable<String> nameChanges = nameDataSource.changes().share(); // One subscriber autoUnsubscribe(nameChanges.subscribe(() -> { ... })); // Another subscriber autoUnsubscribe(nameChanges.map(...).filter(...).subscribe(...)); // autoUnsubscribe is called when the UI is torn down My question is: Why is it necessary to call share() whenever I want to listen to the Observable in multiple places? Why is not share() the default behavior for all observables? It would

Does Functional Reactive Programming in JavaScript cause bigger problems with listener references?

夙愿已清 提交于 2019-12-04 10:05:40
问题 In JavaScript the observer pattern is used quite often. There is one tricky thing with it and that's the references the subject keeps of the observers. They require cleanup. For regular applications I use the following rules of thumb: If the subject has a life span shorter than (or equal to) the observer, I can just do subject.on('event', ...) If the subject has a life span longer than the observer, I need to use observer.listenTo(subject, 'event', ...) In the second case, the listenTo is

With Reactive Extensions (RX), is it possible to add a “Pause” command?

做~自己de王妃 提交于 2019-12-04 08:22:47
I have a class which takes in a stream of events, and pushes out another stream of events. All of the events use Reactive Extensions (RX). The incoming stream of events is pushed from an external source into an IObserver<T> using .OnNext , and the outgoing stream of events is pushed out using IObservable<T> and .Subscribe . I am using Subject<T> to manage this, behind the scenes. I am wondering what techniques there are in RX to pause the output temporarily. This would mean that incoming events would build up in an internal queue, and when they are unpaused, the events would flow out again.

Understanding back-pressure in rxjs - only cache 5 images waiting for upload

∥☆過路亽.° 提交于 2019-12-04 08:22:33
I am working on a node project that needs to submit thousands of images for processing. Before these images are uploaded to the processing server they need to be resized so I have something along the lines of this: imageList .map(image => loadAndResizeImage) .merge(3) .map(image => uploadImage) .merge(3) .subscribe(); Image resizing typically takes a few tenths of a second, uploading and processing takes around 4 seconds. How can I prevent thousands of resized images building up in memory as I wait for the upload queue to clear? I probably want to have 5 images resized and waiting to go so

How cancel task with retrofit and rxjava

纵饮孤独 提交于 2019-12-04 08:05:17
问题 I have rest api. @Get("/serveraction") public Observable<String> myRequest(@Query("Data") String data); I know, that okhttp has canceling functionality(by request object, by tag), but don't know how use it with retrofit and rxjava. What is the best way to realize canceling mechanism for network tasks with retrofit and rxjava? 回答1: You can use the standard RxJava2 cancelling mechanism Disposable. Observable<String> o = retrofit.getObservable(..); Disposable d = o.subscribe(...); // later when

Fighting with FRP

淺唱寂寞╮ 提交于 2019-12-04 07:50:34
I've read about FRP and was very excited. It looks great, so you can write more high-level code, and everything is more composable, and etc. Then I've tried to rewrite my own little game with a few hundreds sloc from plain js to Bacon. And I found that instead of writing high-level logic-only code, I actually beating with Bacon.js and its adherence to principles. I run into some headache that mostly interfere clean code .take(1) Instead of getting value, I should create ugly constructions. Circular dependencies Sometimes they should be by logic. But implementing it in FRP is scary Active state