Skip to content

Commit 053e6fc

Browse files
authored
[Functions] Remove completion-handler based internal logic (#15058)
1 parent 55f72d8 commit 053e6fc

File tree

7 files changed

+75
-253
lines changed

7 files changed

+75
-253
lines changed

FirebaseFunctions/Sources/Functions.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -438,30 +438,6 @@ enum FunctionsConstants {
438438
}
439439
}
440440

441-
func callFunction(at url: URL,
442-
withObject data: Any?,
443-
options: HTTPSCallableOptions?,
444-
timeout: TimeInterval,
445-
completion: @escaping @MainActor (Result<HTTPSCallableResult, Error>) -> Void) {
446-
// Get context first.
447-
contextProvider.getContext(options: options) { context, error in
448-
// Note: context is always non-nil since some checks could succeed, we're only failing if
449-
// there's an error.
450-
if let error {
451-
DispatchQueue.main.async {
452-
completion(.failure(error))
453-
}
454-
} else {
455-
self.callFunction(url: url,
456-
withObject: data,
457-
options: options,
458-
timeout: timeout,
459-
context: context,
460-
completion: completion)
461-
}
462-
}
463-
}
464-
465441
private func callFunction(url: URL,
466442
withObject data: Any?,
467443
options: HTTPSCallableOptions?,

FirebaseFunctions/Sources/HTTPSCallable.swift

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,12 @@ private extension HTTPSCallable {
184184
func call(_ data: sending Any? = nil,
185185
completion: @escaping @MainActor (HTTPSCallableResult?, Error?) -> Void) {
186186
let data = (data as? SendableWrapper)?.value ?? data
187-
if #available(iOS 13, macCatalyst 13, macOS 10.15, tvOS 13, watchOS 7, *) {
188-
Task {
189-
do {
190-
let result = try await call(data)
191-
await completion(result, nil)
192-
} catch {
193-
await completion(nil, error)
194-
}
195-
}
196-
} else {
197-
// This isn’t expected to ever be called because Functions
198-
// doesn’t officially support the older platforms.
199-
functions.callFunction(
200-
at: url,
201-
withObject: data,
202-
options: options,
203-
timeout: timeoutInterval
204-
) { result in
205-
switch result {
206-
case let .success(callableResult):
207-
DispatchQueue.main.async {
208-
completion(callableResult, nil)
209-
}
210-
case let .failure(error):
211-
DispatchQueue.main.async {
212-
completion(nil, error)
213-
}
214-
}
187+
Task {
188+
do {
189+
let result = try await call(data)
190+
await completion(result, nil)
191+
} catch {
192+
await completion(nil, error)
215193
}
216194
}
217195
}

FirebaseFunctions/Sources/Internal/FunctionsContext.swift

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -82,56 +82,4 @@ struct FunctionsContextProvider: Sendable {
8282
}
8383
}
8484
}
85-
86-
func getContext(options: HTTPSCallableOptions? = nil,
87-
_ completion: @escaping ((FunctionsContext, Error?) -> Void)) {
88-
let dispatchGroup = DispatchGroup()
89-
90-
var authToken: String?
91-
var appCheckToken: String?
92-
var error: Error?
93-
var limitedUseAppCheckToken: String?
94-
95-
if let auth {
96-
dispatchGroup.enter()
97-
98-
auth.getToken(forcingRefresh: false) { token, authError in
99-
authToken = token
100-
error = authError
101-
dispatchGroup.leave()
102-
}
103-
}
104-
105-
if let appCheck {
106-
dispatchGroup.enter()
107-
108-
if options?.requireLimitedUseAppCheckTokens == true {
109-
// `getLimitedUseToken(completion:)` is an optional protocol method.
110-
// If it’s not implemented, we still need to leave the dispatch group.
111-
if let limitedUseTokenClosure = appCheck.getLimitedUseToken {
112-
limitedUseTokenClosure { tokenResult in
113-
// In the case of an error, the token will be the placeholder token.
114-
limitedUseAppCheckToken = tokenResult.token
115-
dispatchGroup.leave()
116-
}
117-
} else {
118-
dispatchGroup.leave()
119-
}
120-
} else {
121-
appCheck.getToken(forcingRefresh: false) { tokenResult in
122-
// In the case of an error, the token will be the placeholder token.
123-
appCheckToken = tokenResult.token
124-
dispatchGroup.leave()
125-
}
126-
}
127-
}
128-
129-
dispatchGroup.notify(queue: .main) {
130-
let context = FunctionsContext(authToken: authToken,
131-
fcmToken: self.messaging?.fcmToken,
132-
appCheckToken: appCheckToken,
133-
limitedUseAppCheckToken: limitedUseAppCheckToken)
134-
completion(context, error)
135-
}
136-
}
13785
}

FirebaseFunctions/Tests/CombineUnit/HTTPSCallableTests.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,6 @@ class MockFunctions: Functions, @unchecked Sendable {
4040
return try mockCallFunction()
4141
}
4242

43-
override func callFunction(at url: URL,
44-
withObject data: Any?,
45-
options: HTTPSCallableOptions?,
46-
timeout: TimeInterval,
47-
completion: @escaping @MainActor
48-
(Result<HTTPSCallableResult, any Error>) -> Void) {
49-
do {
50-
try verifyParameters?(url, data, timeout)
51-
let result = try mockCallFunction()
52-
DispatchQueue.main.async {
53-
completion(.success(result))
54-
}
55-
} catch {
56-
DispatchQueue.main.async {
57-
completion(.failure(error))
58-
}
59-
}
60-
}
61-
6243
init(mockCallFunction: @escaping () throws -> HTTPSCallableResult) {
6344
self.mockCallFunction = mockCallFunction
6445
super.init(

0 commit comments

Comments
 (0)