You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* useful when you have multiple independent [Job]s running in parallel.
29
40
*/
30
41
val lambdaScope =CoroutineScope(Dispatchers.Default+SupervisorJob())
42
+
43
+
/**
44
+
* [concurrentFlow] is a [MutableSharedFlow] of [Event]s with a buffer capacity to handle event emissions.
45
+
*
46
+
* Events emitted to this flow are processed by concurrent listeners, allowing for parallel event handling.
47
+
*
48
+
* The buffer overflow strategy is set to [BufferOverflow.DROP_OLDEST], meaning that when the buffer is full,
49
+
* the oldest event will be dropped to accommodate a new event.
50
+
*/
31
51
val concurrentFlow =MutableSharedFlow<Event>(
32
52
extraBufferCapacity =1000,
33
53
onBufferOverflow =BufferOverflow.DROP_OLDEST
34
54
)
35
55
56
+
/**
57
+
* [syncListeners] is a [Subscriber] that manages synchronous listeners.
58
+
*
59
+
* These listeners will be executed immediately when an event is posted, allowing for immediate responses to events.
60
+
* The [syncListeners] are stored in a [Subscriber] object, which is a specialized [ConcurrentHashMap] that manages sets of [Listener]s for different [Event] types.
61
+
*/
36
62
val syncListeners =Subscriber()
63
+
64
+
/**
65
+
* [concurrentListeners] is a [Subscriber] that manages asynchronous listeners.
66
+
*
67
+
* These listeners will be executed in parallel, each on a dedicated coroutine,
68
+
* allowing for concurrent processing of events.
69
+
* The [concurrentListeners] are stored in a [Subscriber] object, which is a specialized [ConcurrentHashMap] that manages sets of [Listener]s for different [Event] types.
70
+
*/
37
71
val concurrentListeners =Subscriber()
38
72
39
73
init {
@@ -49,28 +83,60 @@ object EventFlow {
49
83
}
50
84
}
51
85
52
-
suspendinlinefun <reifiedE : Event> awaitEvent(
86
+
/**
87
+
* Suspends until an event of type [E] is received that satisfies the given [predicate].
88
+
*
89
+
* @param E The type of the event to wait for. This should be a subclass of [Event].
90
+
* @param predicate A lambda to test if the event satisfies the condition.
91
+
* @return The first event that matches the predicate.
0 commit comments