• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Unleash / unleash-android / 10095366255

25 Jul 2024 01:48PM CUT coverage: 82.415% (+0.1%) from 82.319%
10095366255

push

github

web-flow
fix(deps): update dependency androidx.activity:activity-compose to v1.9.1 (#67)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Gastón Fournier <gaston@getunleash.io>

209 of 284 branches covered (73.59%)

Branch coverage included in aggregate %.

644 of 751 relevant lines covered (85.75%)

5.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/unleashandroidsdk/src/main/java/io/getunleash/android/cache/ObservableCache.kt
1
package io.getunleash.android.cache
2

3
import android.util.Log
4
import io.getunleash.android.data.Toggle
5
import io.getunleash.android.data.UnleashState
6
import io.getunleash.android.unleashScope
7
import kotlinx.coroutines.CoroutineScope
8
import kotlinx.coroutines.Dispatchers
9
import kotlinx.coroutines.channels.BufferOverflow
10
import kotlinx.coroutines.flow.Flow
11
import kotlinx.coroutines.flow.MutableSharedFlow
12
import kotlinx.coroutines.flow.asSharedFlow
13
import kotlinx.coroutines.launch
14
import kotlinx.coroutines.withContext
15

16
class ObservableCache(private val cache: ToggleCache, private val coroutineScope: CoroutineScope = unleashScope) : ObservableToggleCache {
9✔
17
    companion object {
18
        private const val TAG = "ObservableCache"
19
    }
20

21
    private var newStateEventFlow = MutableSharedFlow<UnleashState>(
6✔
22
        replay = 1,
1✔
23
        onBufferOverflow = BufferOverflow.DROP_OLDEST
1✔
24
    )
25
    override fun read(): Map<String, Toggle> {
26
        return cache.read()
×
27
    }
28

29
    override fun get(key: String): Toggle? {
30
        return cache.get(key)
5✔
31
    }
32

33
    override fun write(state: UnleashState) {
34
        cache.write(state)
4✔
35
        Log.d(TAG, "Done writing cache with ${newStateEventFlow.subscriptionCount.value} subscribers")
18✔
36
        coroutineScope.launch {
15✔
37
            Log.d(TAG, "Emitting new state with ${state.toggles.size} toggles")
16✔
38
            newStateEventFlow.emit(state)
11✔
39
        }
3✔
40
    }
1✔
41

42
    override fun subscribeTo(featuresReceived: Flow<UnleashState>) {
43
        Log.d(TAG, "Subscribing to observable cache")
4✔
44
        coroutineScope.launch {
15✔
45
            featuresReceived.collect { state ->
14✔
46
                withContext(Dispatchers.IO) {
19!
47
                    Log.d(TAG, "Storing new state with ${state.toggles.size} toggles for $state.context")
21✔
48
                    write(state)
5✔
49
                }
2✔
50
            }
1✔
51
        }
×
52
    }
1✔
53

54
    override fun getUpdatesFlow(): Flow<UnleashState> {
55
        return newStateEventFlow.asSharedFlow()
5✔
56
    }
57
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc