Catch RejectedExecutionException in CompletionService.submit

This commit is contained in:
Dale Wijnand 2018-04-03 16:05:56 +01:00
parent d48aa310e6
commit b78a0f667b
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
2 changed files with 14 additions and 16 deletions

View File

@ -17,7 +17,8 @@ import java.util.concurrent.{
CompletionService => JCompletionService,
Executor,
Executors,
ExecutorCompletionService
ExecutorCompletionService,
RejectedExecutionException,
}
object CompletionService {
@ -33,7 +34,9 @@ object CompletionService {
def take() = completion.take().get()
}
def submit[T](work: () => T, completion: JCompletionService[T]): () => T = {
val future = completion.submit { new Callable[T] { def call = work() } }
val future = try completion.submit { new Callable[T] { def call = work() } } catch {
case _: RejectedExecutionException => throw Incomplete(None, message = Some("cancelled"))
}
() =>
future.get()
}

View File

@ -7,8 +7,6 @@
package sbt
import java.util.concurrent.RejectedExecutionException
import sbt.internal.util.ErrorHandling.wideConvert
import sbt.internal.util.{ DelegatingPMap, IDSet, PMap, RMap, ~> }
import sbt.internal.util.Types._
@ -80,19 +78,16 @@ private[sbt] final class Execute[A[_] <: AnyRef](
def run[T](root: A[T])(implicit strategy: Strategy): Result[T] =
try { runKeep(root)(strategy)(root) } catch { case i: Incomplete => Inc(i) }
def runKeep[T](root: A[T])(implicit strategy: Strategy): RMap[A, Result] =
try {
assert(state.isEmpty, "Execute already running/ran.")
def runKeep[T](root: A[T])(implicit strategy: Strategy): RMap[A, Result] = {
assert(state.isEmpty, "Execute already running/ran.")
addNew(root)
processAll()
assert(results contains root, "No result for root node.")
val finalResults = triggers.onComplete(results)
progressState = progress.allCompleted(progressState, finalResults)
finalResults
} catch {
case _: RejectedExecutionException => throw Incomplete(None, message = Some("cancelled"))
}
addNew(root)
processAll()
assert(results contains root, "No result for root node.")
val finalResults = triggers.onComplete(results)
progressState = progress.allCompleted(progressState, finalResults)
finalResults
}
def processAll()(implicit strategy: Strategy): Unit = {
@tailrec def next(): Unit = {