Skip to content

Instantly share code, notes, and snippets.

@tomas-langer
Last active September 8, 2022 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomas-langer/a61807a6fedeba9c84b49f7278e43bf8 to your computer and use it in GitHub Desktop.
Save tomas-langer/a61807a6fedeba9c84b49f7278e43bf8 to your computer and use it in GitHub Desktop.
Medium-Nima-Reactive-Parallel
// create a dummy stream from numbers 0 to count
Multi.range(0, count)
// for each number, call the task on a different thread
.flatMap(i -> Single.create(CompletableFuture.supplyAsync(() ->
client().get().request(String.class), EXECUTOR))
// flat map from Single<Single<String>> to Single<String>
.flatMap(Function.identity()))
.collectList()
.map(it -> "Combined results: " + it)
.onError(res::send)
.forSingle(res::send);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment