throttleLast vs sample in RxJava

时间:2016-07-11 21:27:28

标签: rx-java

Are there any difference between throttleLast(long, TimeUnit) and sample(long, TimeUnit) of Observable?

Both emit the last item of interval, so they are the same method to me.

If there are differences, what would be the better use case?

1 个答案:

答案 0 :(得分:9)

根据rx-java 1.0.x源代码,它是一样的,因为throttleLast()只是调用sample():

https://github.com/ReactiveX/RxJava/blob/v1.0.16/src/main/java/rx/Observable.java#L8819-L8821