Skip to content

Instantly share code, notes, and snippets.

@jvorhauer
Last active November 4, 2021 13:00
Show Gist options
  • Save jvorhauer/bf70831dec1bc07eb05e43779c718b88 to your computer and use it in GitHub Desktop.
Save jvorhauer/bf70831dec1bc07eb05e43779c718b88 to your computer and use it in GitHub Desktop.
[mono-with-retry] Repeat a GET if the Mono is empty #java
// https://stackoverflow.com/questions/55923326/conditional-repeat-or-retry-on-mono-with-webclient-from-spring-webflux
private Either<Fault, String> poll(final String id) {
JobResponse jr = webClient
.get()
.uri(baseUrl + "/jobs/" + id + "?f=json")
.retrieve()
.bodyToMono(JobResponse.class)
.filter(JobResponse::done)
.repeatWhenEmpty(
Repeat.onlyIf(ctx -> true).timeout(Duration.ofSeconds(10L))
).block();
return jr == null ? Either.left(Fault.serverSide("???")) : Either.right(jr.getJobId());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment