Last active
May 18, 2016 20:58
-
-
Save MishaelRosenthal/5493ee5f75689bad6d72 to your computer and use it in GitHub Desktop.
Throttles the executions
This file contains hidden or 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
| 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