|
| 1 | +import Combine |
1 | 2 | import Foundation |
2 | 3 |
|
3 | 4 | enum ConnectionContinuationError: Error { |
@@ -316,42 +317,45 @@ extension NSXPCConnection { |
316 | 317 |
|
317 | 318 | #if compiler(<6.0) |
318 | 319 | @_unsafeInheritExecutor |
319 | | - public func withDecodingCompletion<Service, Value: Decodable>( |
| 320 | + public func withDecodingCompletion<Service, Value: Decodable, Decoder: TopLevelDecoder>( |
320 | 321 | function: String = #function, |
| 322 | + using decoder: Decoder = JSONDecoder(), |
321 | 323 | _ body: (Service, @escaping @Sendable (Data?, Error?) -> Void) -> Void |
322 | | - ) async throws -> Value { |
| 324 | + ) async throws -> Value where Decoder.Input == Data { |
323 | 325 | let data: Data = try await withValueErrorCompletion(function: function) { service, handler in |
324 | 326 | body(service, handler) |
325 | 327 | } |
326 | 328 |
|
327 | | - return try JSONDecoder().decode(Value.self, from: data) |
| 329 | + return try decoder.decode(Value.self, from: data) |
328 | 330 | } |
329 | 331 | #else |
330 | | - public func withDecodingCompletion<Service, Value: Decodable>( |
| 332 | + public func withDecodingCompletion<Service, Value: Decodable, Decoder: TopLevelDecoder>( |
331 | 333 | isolation: isolated (any Actor)? = #isolation, |
332 | 334 | function: String = #function, |
| 335 | + using decoder: Decoder = JSONDecoder(), |
333 | 336 | _ body: (Service, @escaping (Data?, Error?) -> Void) -> Void |
334 | | - ) async throws -> Value { |
| 337 | + ) async throws -> Value where Decoder.Input == Data { |
335 | 338 | let data: Data = try await withValueErrorCompletion(isolation: isolation, function: function) { service, handler in |
336 | 339 | body(service, handler) |
337 | 340 | } |
338 | 341 |
|
339 | | - return try JSONDecoder().decode(Value.self, from: data) |
| 342 | + return try decoder.decode(Value.self, from: data) |
340 | 343 | } |
341 | 344 | #endif |
342 | 345 |
|
343 | 346 | #if compiler(>=6.0) |
344 | | - @available(*, deprecated, message: "please use withDecodingCompletion(isolation:function:_:)") |
| 347 | + @available(*, deprecated, message: "please use withDecodingCompletion(isolation:function:using:_:)") |
345 | 348 | #endif |
346 | | - public func withDecodingCompletion<Service, Value: Decodable>( |
| 349 | + public func withDecodingCompletion<Service, Value: Decodable, Decoder: TopLevelDecoder>( |
347 | 350 | function: String = #function, |
348 | 351 | on actor: isolated some Actor, |
| 352 | + using decoder: Decoder = JSONDecoder(), |
349 | 353 | _ body: (Service, @escaping @Sendable (Data?, Error?) -> Void) -> Void |
350 | | - ) async throws -> Value { |
| 354 | + ) async throws -> Value where Decoder.Input == Data { |
351 | 355 | let data: Data = try await withValueErrorCompletion(function: function, on: actor) { service, handler in |
352 | 356 | body(service, handler) |
353 | 357 | } |
354 | 358 |
|
355 | | - return try JSONDecoder().decode(Value.self, from: data) |
| 359 | + return try decoder.decode(Value.self, from: data) |
356 | 360 | } |
357 | 361 | } |
0 commit comments