Created
February 25, 2016 22:29
-
-
Save ykrkn/93f80598ae597fcae2ee to your computer and use it in GitHub Desktop.
Infinite stream
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
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