@tokamakdev/platform-android-arm64 0.1.1-beta.131 → 0.1.1-beta.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,7 +8,7 @@ import kotlinx.coroutines.CoroutineScope
|
|
|
8
8
|
import kotlinx.coroutines.CoroutineStart
|
|
9
9
|
import kotlinx.coroutines.Job
|
|
10
10
|
import kotlinx.coroutines.asCoroutineDispatcher
|
|
11
|
-
import kotlinx.coroutines.channels.
|
|
11
|
+
import kotlinx.coroutines.channels.Channel
|
|
12
12
|
import kotlinx.coroutines.flow.Flow
|
|
13
13
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
|
14
14
|
import kotlinx.coroutines.flow.onSubscription
|
|
@@ -64,16 +64,17 @@ class TokamakExporter<P : TokamakPlugin> internal constructor() {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/** How many values
|
|
68
|
-
private const val
|
|
67
|
+
/** How many values wait for the first listener. */
|
|
68
|
+
private const val HELD_CAPACITY = 64
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* The flows of an event's listeners, such as a page's, each of which receives every value [send]
|
|
72
|
-
* delivers while it collects
|
|
73
|
-
*
|
|
72
|
+
* delivers while it collects. A flow keeps every value its collector has not taken, so a Worker's
|
|
73
|
+
* subscription applies its own overflow policy. When [holding], the newest 64 values sent while
|
|
74
|
+
* none listen wait for the first listener.
|
|
74
75
|
*/
|
|
75
76
|
class TokamakListeners<T>(private val holding: Boolean = false) {
|
|
76
|
-
private val values = MutableSharedFlow<T>(extraBufferCapacity =
|
|
77
|
+
private val values = MutableSharedFlow<T>(extraBufferCapacity = Channel.UNLIMITED)
|
|
77
78
|
private val held = mutableListOf<T>()
|
|
78
79
|
|
|
79
80
|
/** A new listener's flow. */
|
|
@@ -86,7 +87,7 @@ class TokamakListeners<T>(private val holding: Boolean = false) {
|
|
|
86
87
|
synchronized(held) {
|
|
87
88
|
if (holding && values.subscriptionCount.value == 0) {
|
|
88
89
|
held += value
|
|
89
|
-
if (held.size >
|
|
90
|
+
if (held.size > HELD_CAPACITY) held.removeAt(0)
|
|
90
91
|
return
|
|
91
92
|
}
|
|
92
93
|
}
|