Skip to content

Commit

Permalink
Allow null return values (for example when the decoding fails and the…
Browse files Browse the repository at this point in the history
… error handler returns null)
  • Loading branch information
janseeger committed Mar 11, 2024
1 parent 18bb2e4 commit 7040a89
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlinx.serialization.serializer
inline fun <reified T: Any> DatabaseReference.toObject(
serializer: KSerializer<T> = serializer<T>(),
crossinline errorHandler: (Throwable) -> T? = { throw it }
): Flow<T> {
): Flow<T?> {
return callbackFlow {
val valueEventListener = object : ValueEventListener {
override fun onCancelled(error: DatabaseError) {
Expand All @@ -32,9 +32,7 @@ inline fun <reified T: Any> DatabaseReference.toObject(
errorHandler(ex)
}

if (decodedAppData != null) {
trySend(decodedAppData)
}
trySend(decodedAppData)
}
}

Expand Down

0 comments on commit 7040a89

Please sign in to comment.