88
99package scala .concurrent
1010
11- import java .util .concurrent .{ Executor }
12- import scala .concurrent ._
11+ import java .util .concurrent .Executor
1312import scala .annotation .tailrec
1413
15- /**
16- * All Batchables are automatically batched when submitted to a BatchingExecutor
17- */
18- private [concurrent] trait Batchable extends Runnable {
19- def isBatchable : Boolean
20- }
21-
2214/**
2315 * Mixin trait for an Executor
2416 * which groups multiple nested `Runnable.run()` calls
@@ -64,13 +56,13 @@ private[concurrent] trait BatchingExecutor extends Executor {
6456 parentBlockContext = prevBlockContext
6557
6658 @ tailrec def processBatch (batch : List [Runnable ]): Unit = batch match {
67- case Nil ⇒ ()
68- case head :: tail ⇒
59+ case Nil => ()
60+ case head :: tail =>
6961 _tasksLocal set tail
7062 try {
7163 head.run()
7264 } catch {
73- case t : Throwable ⇒
65+ case t : Throwable =>
7466 // if one task throws, move the
7567 // remaining tasks to another thread
7668 // so we can throw the exception
@@ -91,7 +83,7 @@ private[concurrent] trait BatchingExecutor extends Executor {
9183 }
9284 }
9385
94- override def blockOn [T ](thunk : ⇒ T )(implicit permission : CanAwait ): T = {
86+ override def blockOn [T ](thunk : => T )(implicit permission : CanAwait ): T = {
9587 // if we know there will be blocking, we don't want to keep tasks queued up because it could deadlock.
9688 {
9789 val tasks = _tasksLocal.get
@@ -111,16 +103,15 @@ private[concurrent] trait BatchingExecutor extends Executor {
111103 override def execute (runnable : Runnable ): Unit = {
112104 if (batchable(runnable)) { // If we can batch the runnable
113105 _tasksLocal.get match {
114- case null ⇒ unbatchedExecute(new Batch (List (runnable))) // If we aren't in batching mode yet, enqueue batch
115- case some ⇒ _tasksLocal.set(runnable :: some) // If we are already in batching mode, add to batch
106+ case null => unbatchedExecute(new Batch (List (runnable))) // If we aren't in batching mode yet, enqueue batch
107+ case some => _tasksLocal.set(runnable :: some) // If we are already in batching mode, add to batch
116108 }
117109 } else unbatchedExecute(runnable) // If not batchable, just delegate to underlying
118110 }
119111
120112 /** Override this to define which runnables will be batched. */
121113 def batchable (runnable : Runnable ): Boolean = runnable match {
122- case b : Batchable ⇒ b.isBatchable
123- case _ : scala.concurrent.OnCompleteRunnable ⇒ true
124- case _ ⇒ false
114+ case _ : OnCompleteRunnable => true
115+ case _ => false
125116 }
126117}
0 commit comments