mirror of
https://github.com/zhigang1992/swift-request.git
synced 2026-01-12 17:52:47 +08:00
Fix ServiceExecutor protocol to require implementation
This commit is contained in:
@@ -5,19 +5,23 @@ public protocol ServiceExecutor {
|
||||
}
|
||||
|
||||
extension ServiceExecutor {
|
||||
public func execute<Output: Decodable>(_ request: Request) async throws -> Output {
|
||||
let (output, _): (Output, _) = try await self.execute(request)
|
||||
public func callAsFunction<Output: Decodable>(_ request: Request) async throws -> Output {
|
||||
let (output, _): (Output, _) = try await self(request)
|
||||
return output
|
||||
}
|
||||
|
||||
public func execute<Output: Decodable>(_ request: Request) async throws -> (Output, HTTPURLResponse) {
|
||||
let (data, response) = try await self.execute(request)
|
||||
public func callAsFunction<Output: Decodable>(_ request: Request) async throws -> (Output, HTTPURLResponse) {
|
||||
let (data, response): (Data, HTTPURLResponse) = try await self.execute(request)
|
||||
let output = try JSONDecoder().decode(Output.self, from: data)
|
||||
return (output, response)
|
||||
}
|
||||
|
||||
public func execute(_ request: Request) async throws -> Data {
|
||||
let (data, _) = try await self.execute(request)
|
||||
public func callAsFunction(_ request: Request) async throws -> Data {
|
||||
let (data, _) = try await self(request)
|
||||
return data
|
||||
}
|
||||
|
||||
public func callAsFunction(_ request: Request) async throws -> (Data, HTTPURLResponse) {
|
||||
return try await execute(request)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class ServiceMethodExpander {
|
||||
|
||||
let codeBlock = CodeBlockSyntax {
|
||||
VariableDeclSyntax(Keyword.let, name: "request", initializer: .init(value: request))
|
||||
ReturnStmtSyntax(expression: "try await executor.execute(request)" as ExprSyntax)
|
||||
ReturnStmtSyntax(expression: "try await executor(request)" as ExprSyntax)
|
||||
}
|
||||
|
||||
let newDeclaration = declaration
|
||||
|
||||
Reference in New Issue
Block a user