Skip to content

Commit 80a3d38

Browse files
committed
Update EventFlow.kt
1 parent 1be0c5a commit 80a3d38

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

common/src/main/kotlin/com/lambda/event/EventFlow.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import kotlinx.coroutines.flow.filterIsInstance
3939
import kotlinx.coroutines.flow.filterNot
4040
import kotlinx.coroutines.flow.first
4141
import kotlinx.coroutines.flow.flow
42-
import kotlinx.coroutines.runBlocking
4342
import kotlinx.coroutines.withTimeout
43+
import kotlin.time.Duration
4444

4545

4646
/**
@@ -127,20 +127,18 @@ object EventFlow {
127127

128128
/**
129129
* Suspends until an event of type [E] is received that satisfies the given [predicate],
130-
* or until the specified [timeout] occurs.
130+
* or until the specified [timeout] passes.
131131
*
132132
* @param E The type of the event to wait for. This should be a subclass of [Event].
133133
* @param timeout The maximum time to wait for the event, in milliseconds.
134134
* @param predicate A lambda to test if the event satisfies the condition.
135135
* @return The first event that matches the predicate or throws a timeout exception if not found.
136136
*/
137137
suspend inline fun <reified E : Event> blockUntilEvent(
138-
timeout: Long,
138+
timeout: Duration,
139139
noinline predicate: (E) -> Boolean = { true },
140-
) = runBlocking {
141-
withTimeout(timeout) {
142-
concurrentFlow.filterIsInstance<E>().first(predicate)
143-
}
140+
) = withTimeout(timeout) {
141+
concurrentFlow.filterIsInstance<E>().first(predicate)
144142
}
145143

146144
/**
@@ -163,7 +161,7 @@ object EventFlow {
163161
* @param predicate A lambda to test if the event satisfies the condition.
164162
* @return A [Flow] emitting events that match the predicate.
165163
*/
166-
suspend inline fun <reified E : Event> collectEvents(
164+
inline fun <reified E : Event> collectEvents(
167165
crossinline predicate: (E) -> Boolean = { true },
168166
): Flow<E> = flow {
169167
concurrentFlow

0 commit comments

Comments
 (0)