Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines
Apache License 2.0
13.06k stars 1.85k forks source link

sample should not start sampling until after the first element is received #2655

Open jonschmidt opened 3 years ago

jonschmidt commented 3 years ago

I don't think the sampling of Flow.sample() should start until after the first element is received. There is even a comment to back that up: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/src/flow/operators/Delay.kt#L298

I am currently running into this problem as I am sampling user drag input and sending network requests to do geo-location. I am using sample to not send too many requests, but it seems that it is delaying the first request as well.

qwwdfsad commented 3 years ago

This behaviour is yet to be designed, but now it's just done consistently with the similar operator from RxJava