Skip to content

Instantly share code, notes, and snippets.

@ova2
Created May 14, 2021 20:38
Show Gist options
  • Save ova2/f54f583c81a6a9e88a363d8921919dad to your computer and use it in GitHub Desktop.
Save ova2/f54f583c81a6a9e88a363d8921919dad to your computer and use it in GitHub Desktop.
public <T> Mono<T> executeMono(Supplier<T> task) {
CompletableFuture<T> future = CompletableFuture.supplyAsync(task);
return Mono.fromFuture(future);
}
public <T> Flux<T> executeFlux(Supplier<List<T>> task) {
return Flux.create((sink) -> {
CompletableFuture<List<T>> future = CompletableFuture.supplyAsync(task);
future.whenComplete((list, exception) -> {
if (exception == null) {
list.forEach(sink::next);
sink.complete();
} else {
sink.error(exception);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment