Skip to content

Commit 278cfbb

Browse files
committed
simplify awaitWhileOnline
1 parent dc939ce commit 278cfbb

File tree

1 file changed

+6
-8
lines changed
  • firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database

1 file changed

+6
-8
lines changed

firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ import kotlin.time.Duration.Companion.seconds
2626
suspend fun <T> Task<T>.awaitWhileOnline(): T =
2727
merge(
2828
flow { emit(await()) },
29-
flow<T> {
30-
Firebase.database
31-
.reference(".info/connected")
32-
.valueEvents
33-
.debounce(2.seconds)
34-
.first { !it.value<Boolean>() }
35-
throw DatabaseException("Database not connected", null)
36-
}
29+
Firebase.database
30+
.reference(".info/connected")
31+
.valueEvents
32+
.debounce(2.seconds)
33+
.filter { !it.value<Boolean>() }
34+
.map<DataSnapshot, T> { throw DatabaseException("Database not connected", null) }
3735
)
3836
.first()
3937

0 commit comments

Comments
 (0)