为什么带有 toList() 的 debounce() 在 RxAndroid 中不起作用?

Why debounce() with toList() doen't working in RxAndroid?

虽然我正在使用debounce(),然后从后端获取数据和数据 我想转换为另一个数据,最后使用 toList()。 当我使用 toList() 时没有任何反应没有任何日志不在订阅和错误中,没有 toList() 它工作并且 subscribe() 方法输入与我有书籍列表一样多,我测试了第二个部分代码没有 debounce() 只是 getItems() 并且使用 toList() 它可以工作。 下面是我的代码,第一部分 debounce()itList() 不起作用,第二部分 toList() 起作用

public Flowable<List<Book>> getItems(String query) {}

textChangeSubscriber
            .debounce(300, TimeUnit.MILLISECONDS)
            .observeOn(Schedulers.computation())
            .switchMap(s -> getItems(s).toObservable())
            .flatMapIterable(items -> items)
            .map(Book::convert)
            .toList()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(books -> {
                Log.i("test", "" + books.toString());
            }, error -> {
                Log.i("test", "" + error);
            });


   getItems(query).flatMapIterable(items -> items)
            .map(Book::convert)
            .toList()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe(books -> {
                Log.i("test", "" + "" + books.toString());
            }, error -> {
                Log.i("test", "" + error);
            });

toList 要求序列终止,这不会发生在响应文本事件的外部流上。您应该将书籍的处理移动到 switchMap:

textChangeSubscriber
        .map(CharSequence::toString) // <-- text components emit mutable CharSequence
        .debounce(300, TimeUnit.MILLISECONDS)
        .observeOn(Schedulers.computation())
        .switchMap(s -> 
              getItems(s)
              .flatMapIterable(items -> items)
              .map(Book::convert)
              .toList()
              .toFlowable() // or toObservable(), depending on textChangeSubscriber
        )
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(books -> {
            Log.i("test", "" + books.toString());
        }, error -> {
            Log.i("test", "" + error);
        });