GeezerVison is showing github.com — fix: use concatEager vs concat courtesy Jake's suggestion · linuxgg/RxJava-Android-Samples@0358361
File tree
Expand file treeCollapse file tree
Open diff view settings
app/src/main/java/com/morihacky/android/rxjava/fragments
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: README.md +3-1Lines changed: 3 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -103,10 +103,12 @@ The value of this technique becomes more apparent when you have more number of i |
103 | 103 |
|
104 | 104 | ### Retrieve data first from a cache, then a network call - using [`.concat`](http://reactivex.io/documentation/operators/concat.html) |
105 | 105 |
|
106 | | -Using concat, you can retrieve information from an observable first (presumably this one is fast like retrieveing from a disk cache) and show preliminary data to a user. Subsequently, when the longer running 2nd observable is complete (say a network call), you can update the results on the interface using the latest information. |
| 106 | +Using concat, you can retrieve information from an observable first (presumably this one is fast like retrieving from a disk cache) and show preliminary data to a user. Subsequently, when the longer running 2nd observable is complete (say a network call), you can update the results on the interface using the latest information. |
107 | 107 |
|
108 | 108 | For the purposes of illustration i use an in-memory `List` (not an actual disk cache), then shoot out a real network call to the github api so it gives you a feel of how this can really be applied in production apps. |
109 | 109 |
|
| 110 | +Note the use of `concatEager` here over the traditional `concat` operator. Both show the results from the `Observables` in a sequential manner (so disk first and then network). The `concat` operator however would not even begin the subscription on subsequent Observables unless the first one is complete whereas `concatEager` kicks off all Observables at the time of Subscription in parallel, but still preserves order. |
| 111 | + |
110 | 112 | **Update:** |
111 | 113 |
|
112 | 114 | After a [conversation I had with @artem_zin](https://twitter.com/kaushikgopal/status/591271805211451392), we arrived at an alternative solution to the same problem. One that used the [`.merge`](http://reactivex.io/documentation/operators/merge.html) operator instead. |
|
Collapse file
Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/PseudoCacheConcatFragment.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,7 +57,7 @@ public void onDemoPseudoCacheClicked() { |
57 | 57 | _resultList.setAdapter(_adapter); |
58 | 58 | _initializeCache(); |
59 | 59 |
|
60 | | - Observable.concat(_getCachedData(), _getFreshData()) |
| 60 | + Observable.concatEager(_getCachedData(), _getFreshData()) |
61 | 61 | .subscribeOn(Schedulers.io()) |
62 | 62 | .observeOn(AndroidSchedulers.mainThread()) |
63 | 63 | .subscribe(new Subscriber<Contributor>() { |
|