mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Room: add extension method awaitAllRoomsAreLoaded with Timeout
This commit is contained in:
+18
-1
@@ -16,13 +16,18 @@
|
||||
|
||||
package io.element.android.libraries.matrix.api.room
|
||||
|
||||
import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import timber.log.Timber
|
||||
import kotlin.time.Duration
|
||||
|
||||
interface RoomSummaryDataSource {
|
||||
|
||||
sealed class LoadingState {
|
||||
object NotLoaded : LoadingState()
|
||||
data class Loaded(val numberOfRooms: Int): LoadingState()
|
||||
data class Loaded(val numberOfRooms: Int) : LoadingState()
|
||||
}
|
||||
|
||||
fun updateAllRoomsVisibleRange(range: IntRange)
|
||||
@@ -30,3 +35,15 @@ interface RoomSummaryDataSource {
|
||||
fun allRooms(): StateFlow<List<RoomSummary>>
|
||||
fun inviteRooms(): StateFlow<List<RoomSummary>>
|
||||
}
|
||||
|
||||
suspend fun RoomSummaryDataSource.awaitAllRoomsAreLoaded(timeout: Duration = Duration.INFINITE) {
|
||||
try {
|
||||
withTimeout(timeout) {
|
||||
allRoomsLoadingState().firstOrNull {
|
||||
it is RoomSummaryDataSource.LoadingState.Loaded
|
||||
}
|
||||
}
|
||||
} catch (timeoutException: TimeoutCancellationException) {
|
||||
Timber.v("AwaitAllRooms: no response after $timeout")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user