feat: Add retry with predicate (#1269)

This commit is contained in:
He-Pin(kerr) 2024-04-23 20:34:16 +08:00 committed by GitHub
parent 64e07dcf1b
commit 77532c1bb5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 500 additions and 37 deletions

View file

@ -85,4 +85,17 @@ public class FutureDocTest extends AbstractJavaTest {
retriedFuture.toCompletableFuture().get(2, SECONDS);
}
@Test
public void useRetryWithPredicate() throws Exception {
// #retry
Callable<CompletionStage<String>> attempt = () -> CompletableFuture.completedFuture("test");
CompletionStage<String> retriedFuture =
Patterns.retry(
attempt, (notUsed, e) -> e != null, 3, java.time.Duration.ofMillis(200), system);
// #retry
retriedFuture.toCompletableFuture().get(2, SECONDS);
}
}