RxJava delay for each item of list emitted

后端 未结 15 1795
感情败类
感情败类 2020-11-29 00:14

I\'m struggling to implement something I assumed would be fairly simple in Rx.

I have a list of items, and I want to have each item emitted with a delay.

It

15条回答
  •  失恋的感觉
    2020-11-29 00:38

    You can use

       Observable.interval(1, TimeUnit.SECONDS)
                .map(new Function() {
                    @Override
                    public Integer apply(Long aLong) throws Exception {
                        return aLong.intValue() + 1;
                    }
                })
                .startWith(0)
                .take(listInput.size())
                .subscribe(new Consumer() {
                    @Override
                    public void accept(Integer index) throws Exception {
                        Log.d(TAG, "---index of your list --" + index);
                    }
                });
    

    This code above not duplicate value(index). "I'm sure"

提交回复
热议问题