Skip to content

Instantly share code, notes, and snippets.

@ramannanda9
Created December 11, 2015 01:15
Show Gist options
  • Save ramannanda9/44116a0abe3d2f6a3461 to your computer and use it in GitHub Desktop.
Save ramannanda9/44116a0abe3d2f6a3461 to your computer and use it in GitHub Desktop.
Rate Limiting requests
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