Skip to content

Commit 9af4a42

Browse files
committed
chore: refactor withRetry to use withRetryAsync
1 parent fadce47 commit 9af4a42

2 files changed

Lines changed: 6 additions & 51 deletions

File tree

sdk/src/main/java/software/amazon/lambda/durable/DurableContext.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,9 @@ <T> DurableFuture<T> waitForConditionAsync(
751751
* @param config retry configuration including the retry strategy and child context wrapping
752752
* @return the operation result
753753
*/
754-
<T> T withRetry(String name, WithRetry<T> operation, WithRetryConfig config);
754+
default <T> T withRetry(String name, WithRetry<T> operation, WithRetryConfig config) {
755+
return withRetryAsync(name, operation, config).get();
756+
}
755757

756758
/**
757759
* Replay-safe retry loop for any durable operation (anonymous form, sync).
@@ -766,7 +768,9 @@ <T> DurableFuture<T> waitForConditionAsync(
766768
* @param config retry configuration including the retry strategy and child context wrapping
767769
* @return the operation result
768770
*/
769-
<T> T withRetry(WithRetry<T> operation, WithRetryConfig config);
771+
default <T> T withRetry(WithRetry<T> operation, WithRetryConfig config) {
772+
return withRetryAsync(operation, config).get();
773+
}
770774

771775
/**
772776
* Replay-safe retry loop for any durable operation (named form, async).

sdk/src/main/java/software/amazon/lambda/durable/context/DurableContextImpl.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -399,55 +399,6 @@ public <T> DurableFuture<T> waitForConditionAsync(
399399
private static final String ANONYMOUS_CHILD_CONTEXT_NAME = "retry";
400400
private static final String ANONYMOUS_BACKOFF_PREFIX = "retry-backoff-";
401401

402-
@Override
403-
@SuppressWarnings("unchecked")
404-
public <T> T withRetry(String name, WithRetry<T> operation, WithRetryConfig config) {
405-
Objects.requireNonNull(name, "name cannot be null");
406-
Objects.requireNonNull(operation, "operation cannot be null");
407-
Objects.requireNonNull(config, "config cannot be null");
408-
409-
if (config.wrapInChildContext()) {
410-
return (T) runInChildContextAsync(
411-
name,
412-
new TypeToken<Object>() {},
413-
childCtx -> executeRetryLoop(childCtx, name, operation, config),
414-
RunInChildContextConfig.builder().build(),
415-
OperationSubType.WITH_RETRY)
416-
.get();
417-
}
418-
return (T) runInVirtualChildContextAsync(
419-
name,
420-
new TypeToken<Object>() {},
421-
childCtx -> executeRetryLoop(childCtx, name, operation, config),
422-
RunInChildContextConfig.builder().build(),
423-
OperationSubType.WITH_RETRY)
424-
.get();
425-
}
426-
427-
@Override
428-
@SuppressWarnings("unchecked")
429-
public <T> T withRetry(WithRetry<T> operation, WithRetryConfig config) {
430-
Objects.requireNonNull(operation, "operation cannot be null");
431-
Objects.requireNonNull(config, "config cannot be null");
432-
433-
if (config.wrapInChildContext()) {
434-
return (T) runInChildContextAsync(
435-
ANONYMOUS_CHILD_CONTEXT_NAME,
436-
new TypeToken<Object>() {},
437-
childCtx -> executeRetryLoop(childCtx, null, operation, config),
438-
RunInChildContextConfig.builder().build(),
439-
OperationSubType.WITH_RETRY)
440-
.get();
441-
}
442-
return (T) runInVirtualChildContextAsync(
443-
ANONYMOUS_CHILD_CONTEXT_NAME,
444-
new TypeToken<Object>() {},
445-
childCtx -> executeRetryLoop(childCtx, null, operation, config),
446-
RunInChildContextConfig.builder().build(),
447-
OperationSubType.WITH_RETRY)
448-
.get();
449-
}
450-
451402
@Override
452403
@SuppressWarnings("unchecked")
453404
public <T> DurableFuture<T> withRetryAsync(String name, WithRetry<T> operation, WithRetryConfig config) {

0 commit comments

Comments
 (0)