Skip to content

Commit 8a518ce

Browse files
committed
feat: check the buffer every second
To reduce overhead of constant loop, the `InMemoryBuffer` will check `buffer` list every second.
1 parent 1905ffc commit 8a518ce

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

parsely/src/main/java/com/parsely/parselyandroid/InMemoryBuffer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.parsely.parselyandroid
22

3+
import kotlin.time.Duration.Companion.seconds
34
import kotlinx.coroutines.CoroutineScope
5+
import kotlinx.coroutines.delay
6+
import kotlinx.coroutines.isActive
47
import kotlinx.coroutines.launch
58
import kotlinx.coroutines.sync.Mutex
69
import kotlinx.coroutines.sync.withLock
@@ -15,13 +18,14 @@ internal class InMemoryBuffer(
1518

1619
init {
1720
coroutineScope.launch {
18-
while (true) {
21+
while (isActive) {
1922
mutex.withLock {
2023
if (buffer.isNotEmpty()) {
2124
localStorageRepository.insertEvents(buffer)
2225
buffer.clear()
2326
}
2427
}
28+
delay(1.seconds)
2529
}
2630
}
2731
}

0 commit comments

Comments
 (0)