Skip to content

Commit

Permalink
Remove eventLoop parameter from async execute APIs (#549)
Browse files Browse the repository at this point in the history
* Remove eventLoop from execute commands

* Remove commented out code
  • Loading branch information
adam-fowler committed Jul 24, 2023
1 parent 94752bf commit b85299b
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 85 deletions.
48 changes: 12 additions & 36 deletions Sources/SotoCore/AWSClient+EndpointDiscovery+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@ extension AWSClient {
httpMethod: HTTPMethod,
serviceConfig: AWSServiceConfig,
endpointDiscovery: AWSEndpointDiscovery,
logger: Logger = AWSClient.loggingDisabled,
on eventLoop: EventLoop? = nil
logger: Logger = AWSClient.loggingDisabled
) async throws {
let eventLoop = eventLoop ?? eventLoopGroup.next()
return try await self.execute(
execute: { endpoint in
return try await self.execute(
operation: operationName,
path: path,
httpMethod: httpMethod,
serviceConfig: endpoint.map { serviceConfig.with(patch: .init(endpoint: $0)) } ?? serviceConfig,
logger: logger,
on: eventLoop
logger: logger
)
},
isEnabled: serviceConfig.options.contains(.enableEndpointDiscovery),
endpointDiscovery: endpointDiscovery,
eventLoop: eventLoop,
logger: logger
)
}
Expand All @@ -72,10 +68,8 @@ extension AWSClient {
input: Input,
hostPrefix: String? = nil,
endpointDiscovery: AWSEndpointDiscovery,
logger: Logger = AWSClient.loggingDisabled,
on eventLoop: EventLoop? = nil
logger: Logger = AWSClient.loggingDisabled
) async throws {
let eventLoop = eventLoop ?? eventLoopGroup.next()
return try await self.execute(
execute: { endpoint in
return try await self.execute(
Expand All @@ -85,13 +79,11 @@ extension AWSClient {
serviceConfig: endpoint.map { serviceConfig.with(patch: .init(endpoint: $0)) } ?? serviceConfig,
input: input,
hostPrefix: hostPrefix,
logger: logger,
on: eventLoop
logger: logger
)
},
isEnabled: serviceConfig.options.contains(.enableEndpointDiscovery),
endpointDiscovery: endpointDiscovery,
eventLoop: eventLoop,
logger: logger
)
}
Expand All @@ -113,24 +105,20 @@ extension AWSClient {
httpMethod: HTTPMethod,
serviceConfig: AWSServiceConfig,
endpointDiscovery: AWSEndpointDiscovery,
logger: Logger = AWSClient.loggingDisabled,
on eventLoop: EventLoop? = nil
logger: Logger = AWSClient.loggingDisabled
) async throws -> Output {
let eventLoop = eventLoop ?? eventLoopGroup.next()
return try await self.execute(
execute: { endpoint in
return try await self.execute(
operation: operationName,
path: path,
httpMethod: httpMethod,
serviceConfig: endpoint.map { serviceConfig.with(patch: .init(endpoint: $0)) } ?? serviceConfig,
logger: logger,
on: eventLoop
logger: logger
)
},
isEnabled: serviceConfig.options.contains(.enableEndpointDiscovery),
endpointDiscovery: endpointDiscovery,
eventLoop: eventLoop,
logger: logger
)
}
Expand All @@ -156,10 +144,8 @@ extension AWSClient {
input: Input,
hostPrefix: String? = nil,
endpointDiscovery: AWSEndpointDiscovery,
logger: Logger = AWSClient.loggingDisabled,
on eventLoop: EventLoop? = nil
logger: Logger = AWSClient.loggingDisabled
) async throws -> Output {
let eventLoop = eventLoop ?? eventLoopGroup.next()
return try await self.execute(
execute: { endpoint in
return try await self.execute(
Expand All @@ -169,13 +155,11 @@ extension AWSClient {
serviceConfig: endpoint.map { serviceConfig.with(patch: .init(endpoint: $0)) } ?? serviceConfig,
input: input,
hostPrefix: hostPrefix,
logger: logger,
on: eventLoop
logger: logger
)
},
isEnabled: serviceConfig.options.contains(.enableEndpointDiscovery),
endpointDiscovery: endpointDiscovery,
eventLoop: eventLoop,
logger: logger
)
}
Expand Down Expand Up @@ -203,10 +187,8 @@ extension AWSClient {
hostPrefix: String? = nil,
endpointDiscovery: AWSEndpointDiscovery,
logger: Logger = AWSClient.loggingDisabled,
on eventLoop: EventLoop? = nil,
stream: @escaping AWSResponseStream
) async throws -> Output {
let eventLoop = eventLoop ?? eventLoopGroup.next()
return try await self.execute(
execute: { endpoint in
return try await self.execute(
Expand All @@ -217,13 +199,11 @@ extension AWSClient {
input: input,
hostPrefix: hostPrefix,
logger: logger,
on: eventLoop,
stream: stream
)
},
isEnabled: serviceConfig.options.contains(.enableEndpointDiscovery),
endpointDiscovery: endpointDiscovery,
eventLoop: eventLoop,
logger: logger
)
}
Expand All @@ -232,21 +212,17 @@ extension AWSClient {
execute: @escaping (String?) async throws -> Output,
isEnabled: Bool,
endpointDiscovery: AWSEndpointDiscovery,
eventLoop: EventLoop,
logger: Logger
) async throws -> Output {
guard isEnabled || endpointDiscovery.isRequired else { return try await execute(nil) }
// get endpoint
if endpointDiscovery.isExpiring(within: 3 * 60) {
do {
let endpointTask = Task { () -> String in
logger.trace("Request endpoint")
let endpoint = try await endpointDiscovery.getEndpoint(logger: logger, on: eventLoop).get()
logger.trace("Received endpoint \(endpoint)")
return endpoint
}
logger.trace("Request endpoint")
let endpoint = try await endpointDiscovery.getEndpoint(logger: logger, on: self.eventLoopGroup.any()).get()
logger.trace("Received endpoint \(endpoint)")

if endpointDiscovery.isRequired {
let endpoint = try await endpointTask.value
return try await execute(endpoint)
} else {
return try await execute(nil)
Expand Down
Loading

0 comments on commit b85299b

Please sign in to comment.