reactive-programming

How to recover from errors in rxjs?

烂漫一生 提交于 2019-12-23 17:58:43
问题 I'm trying to understand how to consume observable sequences and how to recover from errors. My example is a bit contrived but my real implementation is a bit too complex to show here. Anyway, I have someObservable that emits values when the user clicks in the UI. This should trigger a request to the API (GET/POST/etc). The problem is that if the API returns an error, postData isn't called anymore after that. I've make an example here that shows the problem. I've found that I can use Rx

Project Reactor and the Java memory model

拟墨画扇 提交于 2019-12-23 17:23:58
问题 I am trying to understand what guarantees with respect to data visibility Project reactor provides to application code. For e.g. I would expect the below code to fail but it does not after a million iterations. I am changing the state of a typical POJO on thread A and reading it back from thread B. Does Reactor guarantee POJO changes are visible across thread? public class Main { public static void main(String[] args) { Integer result = Flux.range(1, 1_000_000) .map(i -> { Data data = new

Stateful Rsocket Application

£可爱£侵袭症+ 提交于 2019-12-23 14:18:41
问题 in my project I want to have multiple clients connecting to a service. I am using the java Rsocket implementation. The service should maintain a state for each client. Now at this point I either can manage the clients by some identifier. This option I have already implemented. But I do not want to manage the session manually using strings. So another idea is to identify the clients by the Rsocket connection. Is there a way to use Rsocket channel for identification of a specific client?

Reuse subscriber

此生再无相见时 提交于 2019-12-23 12:47:25
问题 In RxJava I have a Subscriber object wich I subscribe on a Observable . Later on (some time after onComplete() has been invoked) I create a new Observable and subscribe with the same Subscriber instance used before. However, that seems not work. Is a subscriber not reusable? Example: class Loader extends Subscriber<T> { public void load(){ Observable.just("Foo").subscribe(this); } public void onComplete(){ // update UI } } In my code I would like to instantiate a Loader once, and call load()

Feedback loop without Subject in RX

回眸只為那壹抹淺笑 提交于 2019-12-23 10:15:17
问题 I have the following motion equations move = target_position - position position = position + move where target_position is a stream and position is initialized at zero. I would like to have a stream of position. I have tried something like this (in rx pseudo code) moves = Subject() position = moves.scan(sum,0) target_position.combine_latest(position,diff).subscribe( moves.on_next) It works but I have read that using Subject should be avoided. Is it possible to compute the position stream

doOnSubscribe gets called on main thread

做~自己de王妃 提交于 2019-12-23 09:29:54
问题 After reading multiple blog posts and documentation, I came to the conclusion that following doOnSubscribe will be executed on a worker thread: Observable.just(1) .observeOn(Schedulers.io()) .doOnSubscribe(__ -> Log.d("Testing", "Testing")) // Shouldn't this be on worker thread? .subscribe(); But after debugging, I see doOnSubscribe is executed on main thread. I thought doOnSubscribe is similar to other operators and hence has similar threading behavior when coupled with subscribeOn and

How to cancel a composed RxJS observable

浪子不回头ぞ 提交于 2019-12-23 05:45:35
问题 Folks, I have an app using RxJS to handle mouse events. I am composing these events into more complex observable 'gestures'. One such gesture is "shake". The series of events I am trying to compose are: mousedown mousemove left mousemove right mousemove left mousemove right mouseup What I am finding is that mousedown mouseup mousemove left mousemove right mousemove left mousemove right is also triggering the same result. I have made a fiddle demonstrating the issue on codepen. My question in

Reactive Extensions and Retry

无人久伴 提交于 2019-12-23 05:45:13
问题 So a series of articles popped on my radar this morning. It started with this question, which lead to the original example and source code on GitHub. I rewrote it slightly, so I can start using it in Console and Service applications: public static class Extensions { static readonly TaskPoolScheduler Scheduler = new TaskPoolScheduler(new TaskFactory()); // Licensed under the MIT license with <3 by GitHub /// <summary> /// An exponential back off strategy which starts with 1 second and then 4,

Accumulating and resetting values in a stream

拥有回忆 提交于 2019-12-23 05:07:51
问题 I'm playing with Reactive Programming, using RxJS, and stumbled upon something I'm not sure how to solve. Let's say we implement a vending machine. You insert a coin, select an item, and the machine dispenses an item and returns change. We'll assume that price is always 1 cent, so inserting a quarter (25 cents) should return 24 cents back, and so on. The "tricky" part is that I'd like to be able to handle cases like user inserting 2 coins and then selecting an item. Or selecting an item

Why I can't access template DOM element in the constructor of the component

与世无争的帅哥 提交于 2019-12-23 03:03:47
问题 Starting with RxJS and want to create a simple stream of button clicks, so I simply do this: export class AppComponent { button : HTMLElement = document.querySelector('button'); refreshClickStream$ = Observable.fromEvent(this.button, 'click') .subscribe(); constructor(){ } but receive that error in console... Also tried it like this: clicked(e) { return Observable.fromEvent(e.target, 'click') .do(console.log) .subscribe(); } But after first click I get no output in console. After second click