ReactiveX / reactivex.github.io

ReactiveX Website
Apache License 2.0
139 stars 139 forks source link

Tutorial Topics #36

Open benjchristensen opened 10 years ago

benjchristensen commented 10 years ago

Issue for tracking discussions about what topics we should have tutorials for. This is slightly different than the normal docs which often are focusing on operators and creation/consumption. This is more for the end-to-end docs, how to solve use cases and problems.

As we agree upon ideas new issues for individual work can be created to track execution.

gyulavoros commented 10 years ago

For RxAndroid I would cover the following topics:

  1. Replacing AsyncTask (better multithreading with Rx)
  2. Understanding Schedulers (be careful with subscribeOn/observeOn)
  3. Create Observables from Android APIs (e.g. ContentProvider, "callback" based APIs)
  4. Manage subscriptions, avoid memory leaks (use Rx in Activity, Fragment, View)
  5. Use Rx for UI operations (e.g. process touch events through Observables) (we don't really use Rx for such things, but could be useful)
  6. REST API clients with Retrofit (native Rx support)
  7. Pitfalls
DavidMGross commented 9 years ago

Here's one we discussed back in August:

"A common question I see is how to do simple event bus use cases. Let's add docs and examples to the wiki."

(Ben C. will come up with code samples. He adds: "Possibly we should link to other projects like Reactor, Disruptor and Vert.x when more advanced event buses are wanted. Ideally we would have RxJava modules for those.")

DavidMGross commented 9 years ago

Here's another from around that time:

"Common questions are related to error handling such as retry, exponential back off, checked exceptions, user functions throwing, and handling different errors differently.

"Let's add a section to the docs with code examples for these things and explaining the Rx contract with idiomatic solutions.

"It should show how to convert from imperative try/catch thinking."

dpkirchner commented 9 years ago

I haven't found a tutorial that describes how to use RxJava to replace an event bus that handles ongoing responses to requests. Almost all tutorials describe how to iterate over a static set of values (some of them how to process a single value) which doesn't seem all that useful. IMO, far too much time is spent on these.

It seems that asynchronous, event-based calls are where RxJava is supposed to shine. I ended up with a solution that I feel is very ugly and might as well be replaced with regular ol' boring callbacks:

class Foo {
  public void connect(Observer<State> observer) {
    Observable.create((subscriber) -> { mSubscriber = subscriber; })
      .subscribe(observer);
  }

  public void changeSomeState(State s) {
    if (mSubscriber != null && !mSubscriber.isUnsubscribed()) {
      mSubscriber.onNext(s);
    }
  }

  public void disconnect() {
    if (mSubscriber != null && !mSubscriber.isUnsubscribed()) {
      mSubscriber.onCompleted();
      mSubscriber.unsubscribe();
      mSubscriber = null;
    }
  }
}

class Bar {
  public void something() {
    Foo foo = new Foo(new Observer<State> {
      public void onNext(State s) {
        // do whatever
      }
      public void onError(Throwable e) {
        // do whatever
      }
    });
  }
}

I must be missing something obvious. There's a lot of boilerplate here.

benjchristensen commented 9 years ago

Here are some sources that may be of interest:

EventBus example: https://gist.github.com/benjchristensen/04eef9ca0851f3a5d7bf HTTP server/client: http://reactivelab.io Parallel execution options: https://gist.github.com/benjchristensen/a0350776a595fd6e3810 Multicast + Zip + Backpressure: https://gist.github.com/benjchristensen/b10c1317c9b538da84c3 Conditional Retry: https://gist.github.com/benjchristensen/fde2e7d2dad2c746a449 Retry with backoff: https://gist.github.com/benjchristensen/3363d420607f03307dd0 OnBackpressureDrop: https://gist.github.com/benjchristensen/9ac4c43737006670872a

Perhaps I should just comb through my many places where I have provided examples and organize them on http://reactivex.io?

dpkirchner commented 9 years ago

I'll check these out. I don't know if there's anything "actionable" at this time, but if I find something that I think could maybe be highlighted somewhere I'll reply to this ticket. Thanks for the links.