Skip to content

Commit

Permalink
Merge pull request #1 from dwijnand/topic/quietly-cancel
Browse files Browse the repository at this point in the history
Catch RejectedExecutionException into an Incomplete
  • Loading branch information
retronym committed Apr 3, 2018
2 parents 70d3484 + b78a0f6 commit 015c310
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
7 changes: 1 addition & 6 deletions main/src/main/scala/sbt/EvaluateTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import sbt.internal.{ Load, BuildStructure, TaskTimings, TaskName, GCUtil }
import sbt.internal.util.{ Attributed, ErrorHandling, HList, RMap, Signals, Types }
import sbt.util.{ Logger, Show }
import sbt.librarymanagement.{ Resolver, UpdateReport }
import java.util.concurrent.RejectedExecutionException

import scala.concurrent.duration.Duration
import java.io.File
Expand Down Expand Up @@ -388,11 +387,7 @@ object EvaluateTask {
val results = x.runKeep(root)(service)
storeValuesForPrevious(results, state, streams)
applyResults(results, state, root)
} catch {
case _: RejectedExecutionException =>
(state, Inc(Incomplete(None, message = Some("cancelled"))))
case inc: Incomplete => (state, Inc(inc))
} finally shutdown()
} catch { case inc: Incomplete => (state, Inc(inc)) } finally shutdown()
val replaced = transformInc(result)
logIncResult(replaced, state, streams)
(newState, replaced)
Expand Down
7 changes: 5 additions & 2 deletions tasks/src/main/scala/sbt/CompletionService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import java.util.concurrent.{
CompletionService => JCompletionService,
Executor,
Executors,
ExecutorCompletionService
ExecutorCompletionService,
RejectedExecutionException,
}

object CompletionService {
Expand All @@ -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()
}
Expand Down
10 changes: 2 additions & 8 deletions tasks/src/main/scala/sbt/Execute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -78,12 +76,8 @@ private[sbt] final class Execute[A[_] <: AnyRef](
"State: " + state.toString + "\n\nResults: " + results + "\n\nCalls: " + callers + "\n\n"

def run[T](root: A[T])(implicit strategy: Strategy): Result[T] =
try {
runKeep(root)(strategy)(root)
} catch {
case i: Incomplete => Inc(i)
case _: RejectedExecutionException => Inc(Incomplete(None, message = Some("cancelled")))
}
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.")

Expand Down

0 comments on commit 015c310

Please sign in to comment.