Skip to content

Commit bdf79b3

Browse files
committed
Improved approach
1 parent 9689fd8 commit bdf79b3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

FirebaseFunctions/Sources/HTTPSCallable.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,15 @@ open class HTTPSCallable: NSObject {
7676
/// - data: Parameters to pass to the trigger.
7777
/// - completion: The block to call when the HTTPS request has completed.
7878
@objc(callWithObject:completion:) open func call(_ data: Any? = nil,
79-
completion: @escaping (HTTPSCallableResult?,
79+
completion: @escaping @MainActor (HTTPSCallableResult?,
8080
Error?) -> Void) {
8181
if #available(iOS 13, macCatalyst 13, macOS 10.15, tvOS 13, watchOS 7, *) {
8282
Task {
8383
do {
8484
let result = try await call(data)
85-
await MainActor.run {
86-
completion(result, nil)
87-
}
85+
await completion(result, nil)
8886
} catch {
89-
await MainActor.run {
90-
completion(nil, error)
91-
}
87+
await completion(nil, error)
9288
}
9389
}
9490
} else {
@@ -102,9 +98,13 @@ open class HTTPSCallable: NSObject {
10298
) { result in
10399
switch result {
104100
case let .success(callableResult):
105-
completion(callableResult, nil)
101+
DispatchQueue.main.async {
102+
completion(callableResult, nil)
103+
}
106104
case let .failure(error):
107-
completion(nil, error)
105+
DispatchQueue.main.async {
106+
completion(nil, error)
107+
}
108108
}
109109
}
110110
}

0 commit comments

Comments
 (0)