Skip to content

Instantly share code, notes, and snippets.

@ykrkn
Created February 25, 2016 22:29
Show Gist options
  • Save ykrkn/93f80598ae597fcae2ee to your computer and use it in GitHub Desktop.
Save ykrkn/93f80598ae597fcae2ee to your computer and use it in GitHub Desktop.
Infinite stream
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
/**
* InfiniteStream.java
* https://gist.github.com/bassemZohdy/e5fdd56de44cea3cd8ff
* Created by sx on 26.02.16.
*/
public class Main {
private final AtomicLong cnt = new AtomicLong();
private void run(){
InfiniteStream<Long> stream = new InfiniteStream<>(1);
ExecutorService es = Executors.newCachedThreadPool();
es.submit(()->{
while (true){
stream.accept(cnt.getAndIncrement());
Thread.sleep(1);
}
});
es.submit(()-> {
stream
.filter(e->e%2==0)
.map(e->e*0.01)
.forEach(e-> System.out.println(e.toString()));
});
}
public static void main(String[] args){
System.out.println("RUN");
new Main().run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment