RxJava delay for each item of list emitted

后端 未结 15 1812
感情败类
感情败类 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:55

    you should be able to achieve this by using Timer operator. I tried with delay but couldn't achieve the desired output. Note nested operations done in flatmap operator.

        Observable.range(1,5)
                .flatMap(x -> Observable.timer(50 * x, TimeUnit.MILLISECONDS)
                            .map(y -> x))
                // attach timestamp
                .timestamp()
                .subscribe(timedIntegers ->
                        Log.i(TAG, "Timed String: "
                                + timedIntegers.value()
                                + " "
                                + timedIntegers.time()));
    

提交回复
热议问题