Skip to content

Instantly share code, notes, and snippets.

@MishaelRosenthal
Last active May 18, 2016 20:58
Show Gist options
  • Select an option

  • Save MishaelRosenthal/5493ee5f75689bad6d72 to your computer and use it in GitHub Desktop.

Select an option

Save MishaelRosenthal/5493ee5f75689bad6d72 to your computer and use it in GitHub Desktop.
Throttles the executions
package core
import java.util.concurrent.ArrayBlockingQueue
class BlockingExecutor(maxParallelism: Int) extends SBLogger{
private case object Execution
private val queue = new ArrayBlockingQueue[Execution.type](maxParallelism)
def execute[T](execution: => T): T = {
queue.put(Execution)
val res = try {
execution
} finally {
queue.poll()
}
res
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment