Fix ServiceExecutor protocol to require implementation

This commit is contained in:
Ailton Vieira
2023-06-28 20:08:42 -03:00
parent a3989c4245
commit 9d5544153c
2 changed files with 11 additions and 7 deletions

View File

@@ -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)
}
}

View File

@@ -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