onNext in observer is never called

0

Consider the following code snippet.

ReplaySubject<List<Object>> subject = ReplaySubject.create();

subject.subscribe(view::mostraListaObjetos);

subject.onNext(getListOnline());
//logo apos essa linha o metodo view.mostrarListaObjetos(lista)
//deveria ser chamado ou estou errado?

The problem is that no matter how many times I call onNext () the observer never gets anything. does anyone have any idea why?

Edited I had summarized the code, but I discovered that this works well, but when I use the flatMapInterable and toList operators, I do not receive anything until subject.onComplete() is called!

Detailed code example.

ReplaySubject<List<Object>> subject = ReplaySubject.create();
subject.flatMapIterable(object -> {
            Log.d(TAG, "flatMapIterable: it is called");
            return object;
        }).doOnEach(objNotification -> Log.d(TAG, "doOnEach: it is called"))
          .toList()
          .subscribe(obj -> Log.d(TAG, "subscribe: it is only called after subscribe.onComplete()"));
subject.onNext(getListOfObjects());
Log.d(TAG, "onComplete:");
subject.onComplete();

Logcat output:

07-04 23:20:38.258 10770-10770/app.package D/TAG: flatMapIterable: it is called
07-04 23:20:38.259 10770-10770/app.package D/TAG: doOnEach: it is called
07-04 23:20:38.259 10770-10770/app.package D/TAG: onComplete:
07-04 23:20:38.260 10770-10770/app.package D/TAG: doOnEach: it is called
07-04 23:20:38.260 10770-10770/app.package D/TAG: it is only called after subscribe.onComplete()
    
asked by anonymous 05.07.2017 / 02:13

1 answer

0

This is the default behavior of the toList () operator, which causes some confusion . As explained in Javadoc , it needs the upstream flag the onComplete to issue the list.

In the diagram you can also see this behavior, as the arrow only exits the toList operator after onComplete upstream :

    
14.12.2017 / 10:21