mirror of
https://github.com/element-hq/element-android
synced 2024-11-22 17:35:37 +03:00
Fix usage of System.currentTimeMillis().
This a bit mocky but anyway it's better to use SystemClock.elapsedRealtime() for this case.
This commit is contained in:
parent
5260e729ac
commit
38641c88b7
1 changed files with 3 additions and 2 deletions
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.lib.core.utils.flow
|
||||
|
||||
import android.os.SystemClock
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
|
@ -68,10 +69,10 @@ fun <T> Flow<T>.chunk(durationInMillis: Long): Flow<List<T>> {
|
|||
|
||||
@ExperimentalCoroutinesApi
|
||||
fun <T> Flow<T>.throttleFirst(windowDuration: Long): Flow<T> = flow {
|
||||
var windowStartTime = System.currentTimeMillis()
|
||||
var windowStartTime = SystemClock.elapsedRealtime()
|
||||
var emitted = false
|
||||
collect { value ->
|
||||
val currentTime = System.currentTimeMillis()
|
||||
val currentTime = SystemClock.elapsedRealtime()
|
||||
val delta = currentTime - windowStartTime
|
||||
if (delta >= windowDuration) {
|
||||
windowStartTime += delta / windowDuration * windowDuration
|
||||
|
|
Loading…
Reference in a new issue