My Realm

A Valentine for my Rx

Check out the second part which proves that this implementation is flawed and doomed.

A bond between Rx and Akka, it just can't get more "Reactive". And with scala passing functions around, it can't be more perfect. No, I am not drunk while I am writing this, what I said might look like rambling, but soon it'll make perfect sense to you.

In Android, a background thread just can't update UI in an easy way. The push model brought by RxJava solves that and a lot more problems, but if you want to observe something indefinitely, it still gets a little messy. For example, you have this remote actor running which is used to listen for incoming messages. The problem is to show them in a textView. Now, how do you do that? Coming straight to the solution, an actor inside an observable which has access to the "observer" will be able to update your textView. Makes sense? No? Okay, Here's the preview code of the project my current startup is based upon.

Easy, wasn't it? All you gotta do is, reassign the reference, subscribe to the observable and finally pass the function you want to get EXECUTED. Voila! you just killed it.

Here's the detailed plan -

Step 1: Declare a non final ActorRef and initialize with null

Step 2: Create an Observable, and inside the definition make a class which extends actor. Reassign this actor's reference to the one in Step 1.

Step 3: Just use onNext to pass everything to the subscriber. Since, the actor class definition is inside the observable definition, it has access to observer.onNext, and hence can forward any message to the subscriber.

Step 4: Subscribe to the observable and to this blog as well.

I am not using remote actors, but if you plan to do, along with this message/chat thing, this solution is perfect. Or maybe it's just me over hyping it.

Bang, okay?(In case you don't know the reference)

No comments:

Post a Comment

I am on Wordpress too.|No Copyright © 2014

Powered by Blogger.