Skip to content

Commit c6fb31b

Browse files
Remove Result type
1 parent 900426b commit c6fb31b

File tree

3 files changed

+12
-12
lines changed
  • firebase-database/src
    • androidMain/kotlin/dev/gitlive/firebase/database
    • iosMain/kotlin/dev/gitlive/firebase/database
    • jsMain/kotlin/dev/gitlive/firebase/database

3 files changed

+12
-12
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ actual class DatabaseReference internal constructor(
191191
.run { Unit }
192192

193193
actual suspend fun <T> runTransaction(strategy: KSerializer<T>, transactionUpdate: (currentData: T) -> T): DataSnapshot {
194-
val deferred = CompletableDeferred<Result<DataSnapshot>>()
194+
val deferred = CompletableDeferred<DataSnapshot>()
195195
android.runTransaction(object : Transaction.Handler {
196196

197197
override fun doTransaction(currentData: MutableData) =
@@ -203,14 +203,14 @@ actual class DatabaseReference internal constructor(
203203
snapshot: com.google.firebase.database.DataSnapshot?
204204
) {
205205
if(error != null) {
206-
throw error.toException()
206+
deferred.completeExceptionally(error.toException())
207207
} else {
208-
deferred.complete(Result.success(DataSnapshot(snapshot!!)))
208+
deferred.complete(DataSnapshot(snapshot!!))
209209
}
210210
}
211211

212212
})
213-
return deferred.await().getOrThrow()
213+
return deferred.await()
214214
}
215215
}
216216
@Suppress("UNCHECKED_CAST")

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,21 @@ actual class DatabaseReference internal constructor(
159159
}
160160

161161
actual suspend fun <T> runTransaction(strategy: KSerializer<T>, transactionUpdate: (currentData: T) -> T): DataSnapshot {
162-
val deferred = CompletableDeferred<Result<DataSnapshot>>()
162+
val deferred = CompletableDeferred<DataSnapshot>()
163163
ios.runTransactionBlock(
164164
block = { firMutableData ->
165165
FIRTransactionResult.successWithValue(transactionUpdate(decode(strategy, firMutableData)) as FIRMutableData)
166166
},
167167
andCompletionBlock = { error, _, snapshot ->
168168
if (error != null) {
169-
throw DatabaseException(error.toString(), null)
169+
deferred.completeExceptionally(DatabaseException(error.toString(), null))
170170
} else {
171-
deferred.complete(Result.success(DataSnapshot(snapshot!!)))
171+
deferred.complete(DataSnapshot(snapshot!!))
172172
}
173173
},
174174
withLocalEvents = false
175175
)
176-
return deferred.await().getOrThrow()
176+
return deferred.await()
177177
}
178178
}
179179

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,19 @@ actual class DatabaseReference internal constructor(override val js: firebase.da
130130
rethrow { js.set(encode(strategy, value, encodeDefaults)).awaitWhileOnline() }
131131

132132
actual suspend fun <T> runTransaction(strategy: KSerializer<T>, transactionUpdate: (currentData: T) -> T): DataSnapshot {
133-
val deferred = CompletableDeferred<Result<DataSnapshot>>()
133+
val deferred = CompletableDeferred<DataSnapshot>()
134134
js.runTransaction(
135135
transactionUpdate,
136136
{ error, _, snapshot ->
137137
if (error != null) {
138-
throw error
138+
deferred.completeExceptionally(error)
139139
} else {
140-
deferred.complete(Result.success(DataSnapshot(snapshot!!)))
140+
deferred.complete(DataSnapshot(snapshot!!))
141141
}
142142
},
143143
applyLocally = false
144144
).await()
145-
return deferred.await().getOrThrow()
145+
return deferred.await()
146146
}
147147

148148
}

0 commit comments

Comments
 (0)