Skip to content

Instantly share code, notes, and snippets.

@chukonu
Created May 7, 2022 10:27
Show Gist options
  • Save chukonu/bfce69e532f6f119a9cf7e7b8939a1cb to your computer and use it in GitHub Desktop.
Save chukonu/bfce69e532f6f119a9cf7e7b8939a1cb to your computer and use it in GitHub Desktop.
Flux.handle example
import reactor.core.publisher.Flux;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class FluxHandleExample {
public static void main(String[] args) throws InterruptedException, ExecutionException {
CompletableFuture<Boolean> completableFuture = new CompletableFuture<>();
Flux.just(0, 1, 2, 3)
.log("ONE")
.<Integer>handle((integer, synchronousSink) -> synchronousSink.next(integer * 10))
.delayElements(Duration.ofSeconds(3))
.log("TWO")
.doOnComplete(() -> completableFuture.complete(true))
.subscribe();
completableFuture.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment