Do you know if it's possible to create Flux of file lines really non-blocking way?
The best solution I've found is next:
Flux.using(
() -> Files.lines(PATH),
Flux::fromStream,
Stream::close
);
Even though it looks non-blocking but it is blocking under the hood.
Read all lines from a file as a Stream. Unlike readAllLines, this method does not read all lines into a List, but instead populates lazily as the stream is consumed.
The returned stream encapsulates a Reader.
Is it possible to create Flux from AsynchronousFileChannel?
Thank you in advance
If you have Spring Framework on classpath, then you can do the following:
Alternatively, you can use RxIo library which provides a nice abstraction similar to
java.nio.file.Filesjust with async/reactive support:Although, it's important to note that even these solutions are not truly non-blocking as depending on the platform (Windows, Linux)
AsynchronousFileChannelimplementation can be blocking under the hood but at least it delegates that task to a dedicated thread pool.