Skip to content

Commit 5f8c8e8

Browse files
authored
fix(database, iOS): ensure transaction handler calls are executed on the main thread (#17953)
1 parent f94bbd6 commit 5f8c8e8

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabasePlugin.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,21 @@ public class FLTFirebaseDatabasePlugin: NSObject, FlutterPlugin, FLTFirebasePlug
255255
let semaphore = DispatchSemaphore(value: 0)
256256
var transactionResult: TransactionHandlerResult?
257257

258-
let flutterApi = FirebaseDatabaseFlutterApi(binaryMessenger: self.binaryMessenger)
259-
flutterApi.callTransactionHandler(
260-
transactionKey: request.transactionKey,
261-
snapshotValue: currentData.value
262-
) { result in
263-
switch result {
264-
case let .success(handlerResult):
265-
transactionResult = handlerResult
266-
case let .failure(error):
267-
print("Transaction handler error: \(error)")
268-
transactionResult = TransactionHandlerResult(value: nil, aborted: true, exception: true)
258+
DispatchQueue.main.async {
259+
let flutterApi = FirebaseDatabaseFlutterApi(binaryMessenger: self.binaryMessenger)
260+
flutterApi.callTransactionHandler(
261+
transactionKey: request.transactionKey,
262+
snapshotValue: currentData.value
263+
) { result in
264+
switch result {
265+
case let .success(handlerResult):
266+
transactionResult = handlerResult
267+
case let .failure(error):
268+
print("Transaction handler error: \(error)")
269+
transactionResult = TransactionHandlerResult(value: nil, aborted: true, exception: true)
270+
}
271+
semaphore.signal()
269272
}
270-
semaphore.signal()
271273
}
272274

273275
semaphore.wait()

0 commit comments

Comments
 (0)