Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Created September 18, 2021 11:37
Show Gist options
  • Select an option

  • Save GaetanoPiazzolla/5a8186355f7a0ccc1e2ab41b0c106426 to your computer and use it in GitHub Desktop.

Select an option

Save GaetanoPiazzolla/5a8186355f7a0ccc1e2ab41b0c106426 to your computer and use it in GitHub Desktop.
import reactor.core.publisher.*;
import java.nio.file.Path;
public Flux<String> searchReactiveParallel(Integer buffer, Integer threads) {
Path ipPath = Path.of(pathFile);
if (buffer == null)
return Flux.using(
() -> Files.lines(ipPath),
Flux::fromStream,
Stream::close)
.subscribeOn(Schedulers.newParallel("searchReactive2", threads))
.share()
.filter(l -> l.contains(SEARCH_TOKEN))
.map(s -> s + "\r\n");
else
return Flux.using(
() -> Files.lines(ipPath),
Flux::fromStream,
Stream::close)
.subscribeOn(Schedulers.newParallel("searchReactive2", threads))
.share()
.buffer(buffer)
.flatMap(l -> Flux.fromStream(
l.stream().filter(line -> line.contains(SEARCH_TOKEN)).map(s -> s + "\r\n")
)
);
}
@GaetanoPiazzolla

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment