1

I'm currently using the Android-ReactiveLocation Library (Github). The LastKnownLocationObservable (Code) is working as intended. I'm using a flatMap to fetch nearby stations from a db and (because of realm) I'm creating a model from the data. So I have a list of items and I'm creating the new Observable in flatMap with Observable.from(data).

Then I want to sort the locations, filter them and group them.

.toSortedList()
.flatMap { Observable.from(it) }
.filter { it.distance <= (maxDistance.toDouble() * 1000) }
.groupBy { //Group the stations in categories
    if (it.distance <= maxDistance && it.favorite) {
        "nearbyFavorite"
    } else if (it.favorite) {
        "outOfReachFavorite"
    } else {
        "nearby"
    }
}

However the onComplete is never called when I subscribe to the Observable. The Observable just stalls at toSortedList().

The Subscribe:

.subscribe(object: Subscriber<GroupedObservable<String, NearbyLocationItem>>() {
    override fun onNext(p0: GroupedObservable<String, NearbyLocationItem>?) {
        val locationItems = ArrayList<NearbyLocationItem>()
        p0.subscribe { loc ->
            locationItems.add(loc)
        }
        locations.put(p0.key, locationItems)
    }


    override fun onCompleted() {
        Log.d(javaClass.simpleName, "Never called")
    }

    override fun onError(p0: Throwable?) {

    }
}
vork
  • 71
  • 1
  • 6
  • Could you add `doOnNext` and `doOnCompleted` at points and see where the events get lost? – akarnokd Feb 24 '16 at 20:54
  • A `OnCompleted` is never triggered and the `OnNext` events stop just before `toSortedList()` – vork Feb 24 '16 at 21:04
  • Maybe you get an exception somewhere but you don't listen to it. – akarnokd Feb 24 '16 at 21:24
  • Wouldn't it show up in the `onError` of the Subscribe? (I have a log there. Just posted a trimmed down version) – vork Feb 24 '16 at 21:53
  • But your `onError` is empty? – zsxwing Feb 24 '16 at 23:31
  • Yep. After the toSortedList the whole thing is dead – vork Feb 24 '16 at 23:44
  • I meant you can add a log in `onError` to check the exception – zsxwing Feb 24 '16 at 23:54
  • There is a log. I posted a trimmed down version. Without the `toSortedList` and the `flatMap` afterwards, I only receive `onNext` Events in the Subscribtion. Yep even without them no `onComplete`. – vork Feb 25 '16 at 00:53
  • 1
    @vork `toList` expects the stream to finish, so it can create a list of all emitted elements. If your observable runs indefinitely it will never get past this statement. – mewa Feb 29 '16 at 23:03

0 Answers0