-
-
Notifications
You must be signed in to change notification settings - Fork 800
Expand file tree
/
Copy pathFlowEventBus.kt
More file actions
36 lines (29 loc) · 1.01 KB
/
FlowEventBus.kt
File metadata and controls
36 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.wikipedia.concurrency
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import org.wikipedia.util.log.L
object FlowEventBus {
private val _events = MutableSharedFlow<Any>(extraBufferCapacity = 8, onBufferOverflow = BufferOverflow.DROP_OLDEST)
val events = _events.asSharedFlow()
fun post(event: Any) {
if (!_events.tryEmit(event)) {
L.e("Unable to emit event")
}
}
}
object AppEventBus {
private val _events = MutableSharedFlow<AppEvent>(replay = 1, extraBufferCapacity = 8, onBufferOverflow = BufferOverflow.DROP_OLDEST)
val events = _events.asSharedFlow()
fun post(event: AppEvent) {
if (!_events.tryEmit(event)) {
_events.tryEmit(event)
}
}
}
sealed class AppEvent {
object ReadingHistoryChanged : AppEvent()
object ImpactChanged : AppEvent()
object DonationsChanged : AppEvent()
object GamesChanged : AppEvent()
}