Merge pull request #4058 from retronym/topic/quietly-cancel

Avoid printing RejectedExectionExeption stack trace after cancellation
This commit is contained in:
Dale Wijnand 2018-04-11 12:00:03 +01:00 committed by GitHub
commit a8c1239e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -4,7 +4,7 @@ import sbt.contraband.ContrabandPlugin.autoImport._
object Dependencies {
// WARNING: Please Scala update versions in PluginCross.scala too
val scala212 = "2.12.4"
val scala212 = "2.12.5"
val baseScalaVersion = scala212
// sbt modules

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

@ -8,7 +8,7 @@
package sbt
import sbt.internal.util.ErrorHandling.wideConvert
import sbt.internal.util.{ DelegatingPMap, PMap, RMap, IDSet, ~> }
import sbt.internal.util.{ DelegatingPMap, IDSet, PMap, RMap, ~> }
import sbt.internal.util.Types._
import Execute._
@ -77,6 +77,7 @@ 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] = {
assert(state.isEmpty, "Execute already running/ran.")