mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Merge pull request #6096 from vector-im/feature/bma/use_clock
Fix usage of System.currentTimeMillis().
This commit is contained in:
commit
6bc97df0bb
@ -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 New Issue
Block a user