Created
December 11, 2015 01:15
-
-
Save ramannanda9/44116a0abe3d2f6a3461 to your computer and use it in GitHub Desktop.
Rate Limiting requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<Movie> invokeRateLimitedFetch(List<SearchedMovie> searchedMovies,boolean saveFile, File file){ | |
List<Movie> movies=new ArrayList<>(); | |
Observable.zip(Observable.from(searchedMovies), | |
Observable.interval(2, TimeUnit.SECONDS), (obs,timer)->obs) | |
.doOnNext(item -> { | |
Movie movie = movieUtil.getMovieDetails(item.getId()); | |
movies.add(movie); | |
if(saveFile) { | |
writeRecordToFile(file, movie); | |
} | |
} | |
).toList().toBlocking().first(); | |
if(csvPrinter!=null){ | |
try { | |
csvPrinter.close(); | |
} catch (IOException e) { | |
} | |
} | |
return movies; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment