Adding How to use it:
public static void main(String[] args) {
InfiniteStream<Integer> is = new InfiniteStream<Integer>(10);
CompletableFuture.runAsync(() -> {
while (true) {
try {
Thread.sleep(1000);
} catch (Exception e) {
throw new RuntimeException(e);
}
IntStream.range(0, 100).boxed().forEach(is);
}
});
is.forEach(System.out::println);
}