mplatvoet
10/05/2015, 9:45 AM//some threadpool with 10 threads
val threadPool = Executors.newFixedThreadPool(10)
//a gate that only allows two processes at any given time
val gate = Gate(maxConcurrentTasks = 2)
//spawn 10 tasks
(1..10).forParallelEach(threadPool) {
//returns immediaty, no matter howw many processes actually are running
//but only 2 are actually running at any given time
//even if there are 10 threads adding
val promise = gate.async {
42 //some long running process
}
//normally do something with the promise
//ommitted for this example
}