@@ -33,23 +33,34 @@ open class HTTPSCallableResult: NSObject {
33
33
34
34
/// A `HTTPSCallable` is a reference to a particular Callable HTTPS trigger in Cloud Functions.
35
35
@objc ( FIRHTTPSCallable)
36
- open class HTTPSCallable : NSObject , @ unchecked Sendable {
36
+ public final class HTTPSCallable : NSObject , Sendable {
37
37
// MARK: - Private Properties
38
38
39
- /// Until this class can be marked *checked* `Sendable`, it's implementation
40
- /// is delegated to an auxiliary class that is checked Sendable.
41
- private let sendableCallable : SendableHTTPSCallable
39
+ // The functions client to use for making calls.
40
+ private let functions : Functions
41
+
42
+ private let url : URL
43
+
44
+ private let options : HTTPSCallableOptions ?
45
+
46
+ private let _timeoutInterval : AtomicBox < TimeInterval > = . init( 70 )
42
47
43
48
// MARK: - Public Properties
44
49
45
50
/// The timeout to use when calling the function. Defaults to 70 seconds.
46
- @objc open var timeoutInterval : TimeInterval {
47
- get { sendableCallable. timeoutInterval }
48
- set { sendableCallable. timeoutInterval = newValue }
51
+ @objc public var timeoutInterval : TimeInterval {
52
+ get { _timeoutInterval. value ( ) }
53
+ set {
54
+ _timeoutInterval. withLock { timeoutInterval in
55
+ timeoutInterval = newValue
56
+ }
57
+ }
49
58
}
50
59
51
60
init ( functions: Functions , url: URL , options: HTTPSCallableOptions ? = nil ) {
52
- sendableCallable = SendableHTTPSCallable ( functions: functions, url: url, options: options)
61
+ self . functions = functions
62
+ self . url = url
63
+ self . options = options
53
64
}
54
65
55
66
/// Executes this Callable HTTPS trigger asynchronously.
@@ -74,11 +85,11 @@ open class HTTPSCallable: NSObject, @unchecked Sendable {
74
85
/// - data: Parameters to pass to the trigger.
75
86
/// - completion: The block to call when the HTTPS request has completed.
76
87
@available ( swift 1000 . 0 ) // Objective-C only API
77
- @objc ( callWithObject: completion: ) open func call( _ data: Any ? = nil ,
78
- completion: @escaping @MainActor ( HTTPSCallableResult ? ,
79
- Error ? )
80
- -> Void ) {
81
- sendableCallable . call ( SendableWrapper ( value: data as Any ) , completion: completion)
88
+ @objc ( callWithObject: completion: ) public func call( _ data: Any ? = nil ,
89
+ completion: @escaping @MainActor ( HTTPSCallableResult ? ,
90
+ Error ? )
91
+ -> Void ) {
92
+ call ( SendableWrapper ( value: data as Any ) , completion: completion)
82
93
}
83
94
84
95
/// Executes this Callable HTTPS trigger asynchronously.
@@ -102,11 +113,19 @@ open class HTTPSCallable: NSObject, @unchecked Sendable {
102
113
/// - Parameters:
103
114
/// - data: Parameters to pass to the trigger.
104
115
/// - completion: The block to call when the HTTPS request has completed.
105
- @nonobjc open func call( _ data: sending Any? = nil ,
106
- completion: @escaping @MainActor ( HTTPSCallableResult ? ,
107
- Error ? )
108
- -> Void ) {
109
- sendableCallable. call ( data, completion: completion)
116
+ @nonobjc public func call( _ data: sending Any? = nil ,
117
+ completion: @escaping @MainActor ( HTTPSCallableResult ? ,
118
+ Error ? )
119
+ -> Void ) {
120
+ let data = ( data as? SendableWrapper ) ? . value ?? data
121
+ Task {
122
+ do {
123
+ let result = try await call ( data)
124
+ await completion ( result, nil )
125
+ } catch {
126
+ await completion ( nil , error)
127
+ }
128
+ }
110
129
}
111
130
112
131
/// Executes this Callable HTTPS trigger asynchronously. This API should only be used from
@@ -142,73 +161,13 @@ open class HTTPSCallable: NSObject, @unchecked Sendable {
142
161
/// - Throws: An error if the Cloud Functions invocation failed.
143
162
/// - Returns: The result of the call.
144
163
@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
145
- open func call( _ data: Any ? = nil ) async throws -> sending HTTPSCallableResult {
146
- try await sendableCallable. call ( data)
164
+ public func call( _ data: Any ? = nil ) async throws -> sending HTTPSCallableResult {
165
+ try await functions
166
+ . callFunction ( at: url, withObject: data, options: options, timeout: timeoutInterval)
147
167
}
148
168
149
169
@available ( macOS 12 . 0 , iOS 15 . 0 , watchOS 8 . 0 , tvOS 15 . 0 , * )
150
170
func stream( _ data: SendableWrapper ? = nil ) -> AsyncThrowingStream < JSONStreamResponse , Error > {
151
- sendableCallable. stream ( data)
152
- }
153
- }
154
-
155
- private extension HTTPSCallable {
156
- final class SendableHTTPSCallable : Sendable {
157
- // MARK: - Private Properties
158
-
159
- // The functions client to use for making calls.
160
- private let functions : Functions
161
-
162
- private let url : URL
163
-
164
- private let options : HTTPSCallableOptions ?
165
-
166
- // MARK: - Public Properties
167
-
168
- let _timeoutInterval = FIRAllocatedUnfairLock < TimeInterval > ( initialState: 70 )
169
-
170
- /// The timeout to use when calling the function. Defaults to 70 seconds.
171
- var timeoutInterval : TimeInterval {
172
- get { _timeoutInterval. value ( ) }
173
- set {
174
- _timeoutInterval. withLock { timeoutInterval in
175
- timeoutInterval = newValue
176
- }
177
- }
178
- }
179
-
180
- init ( functions: Functions , url: URL , options: HTTPSCallableOptions ? = nil ) {
181
- self . functions = functions
182
- self . url = url
183
- self . options = options
184
- }
185
-
186
- func call( _ data: sending Any? = nil ,
187
- completion: @escaping @MainActor ( HTTPSCallableResult ? , Error ? ) -> Void ) {
188
- let data = ( data as? SendableWrapper ) ? . value ?? data
189
- Task {
190
- do {
191
- let result = try await call ( data)
192
- await completion ( result, nil )
193
- } catch {
194
- await completion ( nil , error)
195
- }
196
- }
197
- }
198
-
199
- func __call( completion: @escaping @MainActor ( HTTPSCallableResult ? , Error ? ) -> Void ) {
200
- call ( nil , completion: completion)
201
- }
202
-
203
- @available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
204
- func call( _ data: Any ? = nil ) async throws -> sending HTTPSCallableResult {
205
- try await functions
206
- . callFunction ( at: url, withObject: data, options: options, timeout: timeoutInterval)
207
- }
208
-
209
- @available ( macOS 12 . 0 , iOS 15 . 0 , watchOS 8 . 0 , tvOS 15 . 0 , * )
210
- func stream( _ data: SendableWrapper ? = nil ) -> AsyncThrowingStream < JSONStreamResponse , Error > {
211
- functions. stream ( at: url, data: data, options: options, timeout: timeoutInterval)
212
- }
171
+ functions. stream ( at: url, data: data, options: options, timeout: timeoutInterval)
213
172
}
214
173
}
0 commit comments