File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
firebase-database/src/androidMain/kotlin/dev/teamhub/firebase/database Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import dev.teamhub.firebase.encode
11
11
import kotlinx.coroutines.channels.awaitClose
12
12
import kotlinx.coroutines.coroutineScope
13
13
import kotlinx.coroutines.flow.callbackFlow
14
- import kotlinx.coroutines.flow.conflate
15
14
import kotlinx.coroutines.flow.filter
16
15
import kotlinx.coroutines.flow.produceIn
17
16
import kotlinx.coroutines.selects.select
@@ -21,21 +20,26 @@ import kotlinx.serialization.DeserializationStrategy
21
20
import kotlinx.serialization.SerializationStrategy
22
21
23
22
suspend fun <T > Task<T>.awaitWhileOnline (): T = coroutineScope {
23
+
24
24
val notConnected = Firebase .database
25
25
.reference(" .info/connected" )
26
26
.snapshots
27
27
.filter { ! it.value<Boolean >() }
28
- .conflate()
29
28
.produceIn(this )
30
29
31
- select<T > {
32
- asDeferred().onAwait { it }
33
- notConnected.onReceive { throw DatabaseException (" Database not connected" ) }
30
+ try {
31
+ select<T > {
32
+ asDeferred().onAwait { it }
33
+ notConnected.onReceive { throw DatabaseException (" Database not connected" ) }
34
+ }
35
+ } finally {
36
+ notConnected.cancel()
34
37
}
38
+
35
39
}
36
40
37
41
actual val Firebase .database
38
- get() = FirebaseDatabase (com.google.firebase.database.FirebaseDatabase .getInstance())
42
+ by lazy { FirebaseDatabase (com.google.firebase.database.FirebaseDatabase .getInstance()) }
39
43
40
44
actual fun Firebase.database (url : String ) =
41
45
FirebaseDatabase (com.google.firebase.database.FirebaseDatabase .getInstance(url))
You can’t perform that action at this time.
0 commit comments