RxJava2操作符repeat

发送者发送数据,通过repeat可将数据发送N次,接收者接收N次数据

 Observable sender = Observable.create(new ObservableOnSubscribe() {
        @Override
        public void subscribe(@NonNull ObservableEmitter e) throws Exception {

            e.onNext(1);
            e.onNext(2);
            e.onNext(3);

            e.onComplete();     //必须写,repeat的必要条件
        }
    })
            .repeat(2);         //产生2次重复事件


    Consumer receiver = new Consumer() {
        @Override
        public void accept(@NonNull Integer integer) throws Exception {

            Log.i("zzz","integer: " + integer);

            // 1
            // 2
            // 3
        }
    };

    sender.subscribe(receiver);

你可能感兴趣的:(RxJava2操作符repeat)