Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove eventLoop parameter from async execute APIs #549

Merged
merged 2 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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