Skip to content

Commit fb20ebe

Browse files
committed
Add RibEvents.setExtraBufferCapacity API.
1 parent 9ae7ed1 commit fb20ebe

File tree

1 file changed

+38
-6
lines changed
  • libraries/rib-base/src/main/kotlin/com/uber/rib/core

1 file changed

+38
-6
lines changed

libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibEvents.kt

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,52 @@ import io.reactivex.Observable
2020
import kotlinx.coroutines.channels.BufferOverflow
2121
import kotlinx.coroutines.channels.Channel
2222
import kotlinx.coroutines.flow.MutableSharedFlow
23+
import kotlinx.coroutines.flow.SharedFlow
24+
import kotlinx.coroutines.flow.asSharedFlow
2325
import kotlinx.coroutines.rx2.asObservable
2426

2527
public object RibEvents {
28+
private var extraBufferCapacity: Int = Channel.UNLIMITED
2629

27-
private val mutableRouterEvents =
28-
MutableSharedFlow<RibRouterEvent>(0, Channel.UNLIMITED, BufferOverflow.DROP_OLDEST)
29-
private val mutableRibDurationEvents =
30-
MutableSharedFlow<RibActionInfo>(0, Channel.UNLIMITED, BufferOverflow.DROP_OLDEST)
30+
/**
31+
* Sets the extra buffer capacity for [routerEventsFlow] and [ribActionEventsFlow].
32+
*
33+
* This function must be called on the main thread, and before any usage of:
34+
* 1. [routerEventsFlow]
35+
* 2. [routerEvents]
36+
* 3. [ribActionEventsFlow]
37+
* 4. [ribActionEvents]
38+
*/
39+
@JvmStatic
40+
public fun setExtraBufferCapacity(capacity: Int) {
41+
extraBufferCapacity = capacity
42+
}
43+
44+
private val mutableRouterEvents by lazy {
45+
MutableSharedFlow<RibRouterEvent>(0, extraBufferCapacity, BufferOverflow.DROP_OLDEST)
46+
}
47+
48+
private val mutableRibDurationEvents by lazy {
49+
MutableSharedFlow<RibActionInfo>(0, extraBufferCapacity, BufferOverflow.DROP_OLDEST)
50+
}
51+
52+
@JvmStatic
53+
public val routerEventsFlow: SharedFlow<RibRouterEvent> by lazy {
54+
mutableRouterEvents.asSharedFlow()
55+
}
3156

3257
@JvmStatic
33-
public val routerEvents: Observable<RibRouterEvent> = mutableRouterEvents.asObservable()
58+
public val routerEvents: Observable<RibRouterEvent> by lazy { mutableRouterEvents.asObservable() }
3459

3560
@JvmStatic
36-
public val ribActionEvents: Observable<RibActionInfo> = mutableRibDurationEvents.asObservable()
61+
public val ribActionEventsFlow: SharedFlow<RibActionInfo> by lazy {
62+
mutableRibDurationEvents.asSharedFlow()
63+
}
64+
65+
@JvmStatic
66+
public val ribActionEvents: Observable<RibActionInfo> by lazy {
67+
mutableRibDurationEvents.asObservable()
68+
}
3769

3870
internal var useStateFlowInteractorEvent: Boolean = false
3971
private set

0 commit comments

Comments
 (0)