reactive-programming

Difference between catch: and subscribeError:

耗尽温柔 提交于 2019-12-02 16:19:26
In ReactiveCocoa , what's the difference between the subscribeError: method vs. catch: ? Why would you want to return a signal in catch: ? -subscribeError: actually subscribes: this is the end of the line. Whereas -catch: simply transforms a signal into a new signal (and doesn't actually subscribe). Think of the signal like a program. When you -subscribeError: , you are telling the computer "I want to run this program, but I only want to hear back from you if it errors out." When you -catch: , you are saying "I've got this program that may throw an error, and I want to make a new one based on

Subscribewith Vs subscribe in RxJava2(Android)?

a 夏天 提交于 2019-12-02 15:29:42
When to call the subscribeWith method rather than plain subscribe? And what is the use case? compositeDisposable.add(get() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(this::handleResponse, this::handleError)); VS compositeDisposable.add(get() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) // .subscribe(this::handleResponse, this::handleError); .subscribeWith(new DisposableObserver<News>() { @Override public void onNext(News value) { handleResponse(value); } @Override public void onError(Throwable e) { handleError(e); } @Override

What are the reference ownership semantics of ReactiveCocoa?

我怕爱的太早我们不能终老 提交于 2019-12-02 14:18:34
When I create a signal and bring it into the scope of a function, its effective retain count is 0 per Cocoa conventions: RACSignal *signal = [self createSignal]; When I subscribe to the signal, it retains the subscriber and returns a disposable which, per Cocoa conventions, also has a retain count of zero. RACDisposable *disposable = [signal subscribeCompleted:^ { doSomethingPossiblyInvolving(self); }]; Most of the time, the subscriber will close over and reference self or its ivars or some other part of the enclosing scope. So when you subscribe to a signal, the signal has an owning reference

Splitting an RACSignal to eliminate state

纵饮孤独 提交于 2019-12-02 14:15:37
I'm using ReactiveCocoa to update a UILabel whilst a UIProgressView counts down: NSInteger percentRemaining = ...; self.progressView.progress = percentRemaining / 100.0; __block NSInteger count = [self.count]; [[[RACSignal interval:0.05 onScheduler:[RACScheduler mainThreadScheduler]] take: percentRemaining] subscribeNext:^(id x) { count++; self.countLabel.text = [NSString stringWithFormat:@"%d", count]; self.progressView.progress = self.progressView.progress - 0.01; } completed:^{ // Move along... }]; This works well enough but, I'm not particularly happy with either the count variable or with

Reactive Programming - RxJS vs EventEmitter in Node.js

佐手、 提交于 2019-12-02 14:14:08
Recently I've started looking at RxJS and RxJava(from Netflix) libraries which work on the concept of Reactive Programming. Node.js works on the basis of event loops, which provides you all the arsenal for asynchronous programming and the subsequent node libraries like "cluster" help you to get best out of your multi-core machine. And Node.js also provides you the EventEmitter functionality where you can subscribe to events and act upon it asynchronously. On the other hand if I understand correctly RxJS (and Reactive Programming in general) works on the principle of event streams, subscribing

RxJS: How would I “manually” update an Observable?

别来无恙 提交于 2019-12-02 13:56:02
I think I must be misunderstanding something fundamental, because in my mind this should be the most basic case for an an observable, but for the life of my I can't figure out how to do it from the docs. Basically, I want to be able to do this: // create a dummy observable, which I would update manually var eventObservable = rx.Observable.create(function(observer){}); var observer = eventObservable.subscribe( function(x){ console.log('next: ' + x); } ... var my_function = function(){ eventObservable.push('foo'); //'push' adds an event to the datastream, the observer gets it and prints // next:

The difference between Reactive and Functional-Reactive programming

亡梦爱人 提交于 2019-12-02 13:55:41
I have been doing some research into reactive programming recently and I'm finding it hard to find a good description of the difference between Reactive and Functional -Reactive. Is it simply that the reactive programming is implemented using functional methods/paradigms as opposed to using declarative or OO paradigms? Conal Functional Reactive Programming (FRP) is a specific programming model with a specific semantics. (Actually, there are two variants, which are sometimes called "classic FRP" and "arrow FRP".) I've given a summary in an answer to "What is (functional) reactive programming?"

How to ensure that all observers see the same result from multiple parallel subscription

只谈情不闲聊 提交于 2019-12-02 11:34:38
I have two observables. First - get session from internet or from cache; Observable<SessionKey> getSession = getSessionFromInternetOrCache(); Second - call to server api, using session Observable<MyResult> apiCall = getSession.flatMap(session -> { return myApi.getResult(session); }) Problem, that I have several independent components (gui). They are starting in parallel. apiCall also started in parallel. And i gets several session keys. What behavior I want: getSessions should calling once, other observables waiting first getSessions call. After first getSessions calling, all getSessions will

Rxjs - Consume API output and re-query when cache is empty

梦想与她 提交于 2019-12-02 10:54:10
问题 I'm trying to implement a version of this intro to RxJS (fiddle here) that instead of picking a random object from a returned API array, it consumes a backthrottled stream of objects from the returned API array. Here's a portion of the code that produces a controlled Observable from the API response (full fiddle here): var responseStream = requestStream.flatMap(function (requestUrl) { return Rx.Observable.fromPromise(fetch(requestUrl)); }).flatMap(function(response) { return Rx.Observable

refactor fat arrow nested rxjs stream

浪尽此生 提交于 2019-12-02 09:41:36
I am playing with http://reactivex.io/learnrx/ . In better effort to learn rxjs. The array that I am working through is below. I am just trying to get the id's out of the array. I am able to get the answer to work but feel that answer could be better written. var movieLists = [ { name: "New Releases", videos: [ { "id": 70111470, "title": "Die Hard", "boxart": "http://cdn-0.nflximg.com/images/2891/DieHard.jpg", "uri": "http://api.netflix.com/catalog/titles/movies/70111470", "rating": 4.0, "bookmark": [] }, { "id": 654356453, "title": "Bad Boys", "boxart": "http://cdn-0.nflximg.com/images/2891