RxJava 操作符 concat

Concat操作符


public void test() {
    Observable.concat(Observable.just("a"), Observable.just("b"), Observable.just("c")).subscribe(
        new Observer<String>() {
          @Override public void onCompleted() {
            Log.e("test---onCompleted ", "onCompleted");
          }

          @Override public void onError(Throwable e) {

          }

          @Override public void onNext(String s) {

            Log.e("test---onNext ", "onNext s : " + s);
          }
        });
  }


04-22 16:44:43.822  28030-28030/com.fernandocejas.android10.sample.presentation E/test---onNext﹕ onNext s : a
04-22 16:44:43.822  28030-28030/com.fernandocejas.android10.sample.presentation E/test---onNext﹕ onNext s : b
04-22 16:44:43.822  28030-28030/com.fernandocejas.android10.sample.presentation E/test---onNext﹕ onNext s : c
04-22 16:44:43.822  28030-28030/com.fernandocejas.android10.sample.presentation E/test---onCompleted﹕ onCompleted


可以将该操作符看作,依次将多个数据源释放到同一个地方。


/**
     * Returns an Observable that emits the items emitted by three Observables, one after the other, without
     * interleaving them.
     * <p>
     * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/concat.png" alt="">
     * <dl>
     *  <dt><b>Scheduler:</b></dt>
     *  <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
     * </dl>
     *
     * @param t1
     *            an Observable to be concatenated
     * @param t2
     *            an Observable to be concatenated
     * @param t3
     *            an Observable to be concatenated
     * @return an Observable that emits items emitted by the three source Observables, one after the other,
     *         without interleaving them
     * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>
     */
    public final static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3) {
        return concat(just(t1, t2, t3));
    }


你可能感兴趣的:(RxJava 操作符 concat)