Skip to content

Instantly share code, notes, and snippets.

@ashikuzzaman-ar
Created February 15, 2022 07:02
Show Gist options
  • Save ashikuzzaman-ar/8ce42a2493e179af48d94860be68f9bc to your computer and use it in GitHub Desktop.
Save ashikuzzaman-ar/8ce42a2493e179af48d94860be68f9bc to your computer and use it in GitHub Desktop.
What if you have no choice to call some blocking codebase from a legacy library or some legacy system. This is a way arround for the problem. Though this is not reactive but at least it's non blocking.
@Test
void callingBlockingCodeInReactiveStreams() {
Mono.fromCallable(() -> {
// Your blocking code here
return new Object();
}).subscribeOn(Schedulers.boundedElastic());
Flux.fromIterable(Stream.of(1, 2, 3, 4, 5).map(i -> {
// Your blocking code here
return new Object();
}).toList())
.subscribeOn(Schedulers.boundedElastic());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment