Buffering, throttling, and debouncing
Here is one interesting example:
Path path = Paths.get("src", "main", "resources"); Observable<String> data = CreateObservable .listFolder(path, "*") .flatMap(file -> { if (!Files.isDirectory(file)) { return CreateObservable .from(file) .subscribeOn(Schedulers.io()); } return Observable.empty(); }); subscribePrint(data, "Too many lines");
This goes through all the files in a folder and reads all of them in parallel if they are not folders themselves. For the example, while I'm running it, there are five text files in the folder, and one of them is quite large. While printing the content of these files with our subscribePrint()
method, we get something that looks like this:
Too many lines : Morbi nec nulla ipsum. ...
Get Learning Reactive Programming with Java 8 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.