File tree Expand file tree Collapse file tree 3 files changed +12
-12
lines changed
androidMain/kotlin/dev/gitlive/firebase/database
iosMain/kotlin/dev/gitlive/firebase/database
jsMain/kotlin/dev/gitlive/firebase/database Expand file tree Collapse file tree 3 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ actual class DatabaseReference internal constructor(
191
191
.run { Unit }
192
192
193
193
actual suspend fun <T > runTransaction (strategy : KSerializer <T >, transactionUpdate : (currentData: T ) -> T ): DataSnapshot {
194
- val deferred = CompletableDeferred <Result < DataSnapshot > >()
194
+ val deferred = CompletableDeferred <DataSnapshot >()
195
195
android.runTransaction(object : Transaction .Handler {
196
196
197
197
override fun doTransaction (currentData : MutableData ) =
@@ -203,14 +203,14 @@ actual class DatabaseReference internal constructor(
203
203
snapshot : com.google.firebase.database.DataSnapshot ?
204
204
) {
205
205
if (error != null ) {
206
- throw error.toException()
206
+ deferred.completeExceptionally( error.toException() )
207
207
} else {
208
- deferred.complete(Result .success( DataSnapshot (snapshot!! ) ))
208
+ deferred.complete(DataSnapshot (snapshot!! ))
209
209
}
210
210
}
211
211
212
212
})
213
- return deferred.await().getOrThrow()
213
+ return deferred.await()
214
214
}
215
215
}
216
216
@Suppress(" UNCHECKED_CAST" )
Original file line number Diff line number Diff line change @@ -159,21 +159,21 @@ actual class DatabaseReference internal constructor(
159
159
}
160
160
161
161
actual suspend fun <T > runTransaction (strategy : KSerializer <T >, transactionUpdate : (currentData: T ) -> T ): DataSnapshot {
162
- val deferred = CompletableDeferred <Result < DataSnapshot > >()
162
+ val deferred = CompletableDeferred <DataSnapshot >()
163
163
ios.runTransactionBlock(
164
164
block = { firMutableData ->
165
165
FIRTransactionResult .successWithValue(transactionUpdate(decode(strategy, firMutableData)) as FIRMutableData )
166
166
},
167
167
andCompletionBlock = { error, _, snapshot ->
168
168
if (error != null ) {
169
- throw DatabaseException (error.toString(), null )
169
+ deferred.completeExceptionally( DatabaseException (error.toString(), null ) )
170
170
} else {
171
- deferred.complete(Result .success( DataSnapshot (snapshot!! ) ))
171
+ deferred.complete(DataSnapshot (snapshot!! ))
172
172
}
173
173
},
174
174
withLocalEvents = false
175
175
)
176
- return deferred.await().getOrThrow()
176
+ return deferred.await()
177
177
}
178
178
}
179
179
Original file line number Diff line number Diff line change @@ -130,19 +130,19 @@ actual class DatabaseReference internal constructor(override val js: firebase.da
130
130
rethrow { js.set(encode(strategy, value, encodeDefaults)).awaitWhileOnline() }
131
131
132
132
actual suspend fun <T > runTransaction (strategy : KSerializer <T >, transactionUpdate : (currentData: T ) -> T ): DataSnapshot {
133
- val deferred = CompletableDeferred <Result < DataSnapshot > >()
133
+ val deferred = CompletableDeferred <DataSnapshot >()
134
134
js.runTransaction(
135
135
transactionUpdate,
136
136
{ error, _, snapshot ->
137
137
if (error != null ) {
138
- throw error
138
+ deferred.completeExceptionally( error)
139
139
} else {
140
- deferred.complete(Result .success( DataSnapshot (snapshot!! ) ))
140
+ deferred.complete(DataSnapshot (snapshot!! ))
141
141
}
142
142
},
143
143
applyLocally = false
144
144
).await()
145
- return deferred.await().getOrThrow()
145
+ return deferred.await()
146
146
}
147
147
148
148
}
You can’t perform that action at this time.
0 commit comments