Skip to content

Instantly share code, notes, and snippets.

@aloiscochard
Created August 24, 2011 18:37
Show Gist options
  • Save aloiscochard/1168816 to your computer and use it in GitHub Desktop.
Save aloiscochard/1168816 to your computer and use it in GitHub Desktop.
Scala Parallel Compiler Plugin
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