Skip to content

Commit 9db2770

Browse files
committed
make sure notConnected is cancelled
1 parent 4506d36 commit 9db2770

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ subprojects {
174174
}
175175

176176
dependencies {
177-
"jvmMainApi"("dev.gitlive:firebase-java-sdk:1.0.17")
177+
"jvmMainApi"("dev.gitlive:firebase-java-sdk:1.0.18")
178178
"jvmMainApi"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.0") {
179179
exclude("com.google.android.gms")
180180
}

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,28 @@
55
package dev.gitlive.firebase.database
66

77
import com.google.android.gms.tasks.Task
8-
import com.google.firebase.database.ChildEventListener
9-
import com.google.firebase.database.DatabaseError
10-
import com.google.firebase.database.Logger
11-
import com.google.firebase.database.MutableData
12-
import com.google.firebase.database.Transaction
13-
import com.google.firebase.database.ValueEventListener
14-
import dev.gitlive.firebase.encode
8+
import com.google.firebase.database.*
159
import dev.gitlive.firebase.Firebase
1610
import dev.gitlive.firebase.FirebaseApp
1711
import dev.gitlive.firebase.database.ChildEvent.Type
18-
import dev.gitlive.firebase.decode
1912
import dev.gitlive.firebase.database.FirebaseDatabase.Companion.FirebaseDatabase
20-
import kotlinx.coroutines.CancellationException
13+
import dev.gitlive.firebase.decode
14+
import dev.gitlive.firebase.encode
15+
import kotlinx.coroutines.CompletableDeferred
2116
import kotlinx.coroutines.channels.awaitClose
17+
import kotlinx.coroutines.channels.trySendBlocking
2218
import kotlinx.coroutines.coroutineScope
19+
import kotlinx.coroutines.flow.Flow
20+
import kotlinx.coroutines.flow.callbackFlow
21+
import kotlinx.coroutines.flow.filter
22+
import kotlinx.coroutines.flow.produceIn
2323
import kotlinx.coroutines.selects.select
2424
import kotlinx.coroutines.tasks.asDeferred
2525
import kotlinx.coroutines.tasks.await
26-
import kotlinx.coroutines.CompletableDeferred
27-
import kotlinx.coroutines.cancel
28-
import kotlinx.coroutines.channels.trySendBlocking
29-
import kotlinx.coroutines.flow.*
3026
import kotlinx.serialization.DeserializationStrategy
3127
import kotlinx.serialization.KSerializer
3228
import kotlinx.serialization.SerializationStrategy
33-
import java.util.WeakHashMap
29+
import java.util.*
3430

3531
suspend fun <T> Task<T>.awaitWhileOnline(): T = coroutineScope {
3632

@@ -40,9 +36,13 @@ suspend fun <T> Task<T>.awaitWhileOnline(): T = coroutineScope {
4036
.filter { !it.value<Boolean>() }
4137
.produceIn(this)
4238

43-
select<T> {
44-
asDeferred().onAwait { it.also { notConnected.cancel() } }
45-
notConnected.onReceive { throw DatabaseException("Database not connected", null) }
39+
try {
40+
select<T> {
41+
asDeferred().onAwait { it }
42+
notConnected.onReceive { throw DatabaseException("Database not connected", null) }
43+
}
44+
} finally {
45+
notConnected.cancel()
4646
}
4747
}
4848

0 commit comments

Comments
 (0)