Created
August 24, 2011 18:37
-
-
Save aloiscochard/1168816 to your computer and use it in GitHub Desktop.
Scala Parallel Compiler Plugin
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.ScheduledThreadPoolExecutor | |
import java.util.concurrent.TimeUnit | |
import scala.actors.scheduler.ExecutorScheduler | |
import scala.tools.nsc | |
import nsc.Phase | |
import nsc.plugins.PluginComponent | |
abstract class ParallelPluginComponent extends PluginComponent { | |
import global._ | |
abstract class ParallelPhase(prev: Phase) extends StdPhase(prev) { | |
protected val timeout = 10 * 1000 | |
protected val executor = new ScheduledThreadPoolExecutor(Runtime.getRuntime.availableProcessors) | |
protected val scheduler = ExecutorScheduler(executor) | |
override def run() = { | |
super.run() | |
scheduler.shutdown | |
executor.awaitTermination(timeout, TimeUnit.MILLISECONDS) | |
} | |
def async(unit: CompilationUnit): Unit | |
final def apply(unit: CompilationUnit) = scheduler.execute { async(unit) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment