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

Update schedule retry API to return retry token #125

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 6 additions & 5 deletions Source/AwsCommonRuntimeKit/io/retryer/RetryStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public class RetryStrategy {
}
}

public func scheduleRetry(token: RetryToken, errorType: RetryError) async throws {
try await withCheckedThrowingContinuation({ (continuation: CheckedContinuation<(), Error>) in
public func scheduleRetry(token: RetryToken, errorType: RetryError) async throws -> RetryToken {
try await withCheckedThrowingContinuation { continuation in
let continuationCore = ContinuationCore(continuation: continuation)
if aws_retry_strategy_schedule_retry(token.rawValue,
errorType.rawValue,
Expand All @@ -81,7 +81,7 @@ public class RetryStrategy {
continuationCore.release()
continuation.resume(throwing: CommonRunTimeError.crtError(.makeFromLastError()))
}
})
}
}

/// Records a successful retry.You should always call it after a successful operation
Expand All @@ -98,14 +98,15 @@ public class RetryStrategy {
private func onRetryReady(token: UnsafeMutablePointer<aws_retry_token>?,
errorCode: Int32,
userData: UnsafeMutableRawPointer!) {
let crtRetryStrategyCore = Unmanaged<ContinuationCore<()>>.fromOpaque(userData).takeRetainedValue()
let crtRetryStrategyCore = Unmanaged<ContinuationCore<RetryToken>>.fromOpaque(userData).takeRetainedValue()
if errorCode != AWS_OP_SUCCESS {
crtRetryStrategyCore.continuation.resume(throwing: CommonRunTimeError.crtError(CRTError(code: errorCode)))
return
}

// Success
crtRetryStrategyCore.continuation.resume()
aws_retry_token_acquire(token!)
crtRetryStrategyCore.continuation.resume(returning: RetryToken(rawValue: token!))
}

private func onRetryTokenAcquired(retry_strategy: UnsafeMutablePointer<aws_retry_strategy>?,
Expand Down
2 changes: 1 addition & 1 deletion Test/AwsCommonRuntimeKitTests/io/RetryerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class RetryerTests: XCBaseTestCase {
let retryer = try RetryStrategy(eventLoopGroup: elg, allocator: allocator)
let token = try await retryer.acquireToken(partitionId: "partition1")
XCTAssertNotNil(token)
try await retryer.scheduleRetry(token: token, errorType: RetryError.serverError)
_ = try await retryer.scheduleRetry(token: token, errorType: RetryError.serverError)
}
}