Merge pull request #5450 from azolotko/handle-interrupted-exception-in-completion-service-task

Treat InterruptedException in CompletionService as task cancelation
This commit is contained in:
eugene yokota 2020-02-26 16:31:31 -05:00 committed by GitHub
commit 8b74261092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -34,8 +34,19 @@ object CompletionService {
def take() = completion.take().get()
}
def submit[T](work: () => T, completion: JCompletionService[T]): () => T = {
val future = try completion.submit { new Callable[T] { def call = work() } } catch {
case _: RejectedExecutionException => throw Incomplete(None, message = Some("cancelled"))
val future = try completion.submit {
new Callable[T] {
def call =
try {
work()
} catch {
case _: InterruptedException =>
throw Incomplete(None, message = Some("cancelled"))
}
}
} catch {
case _: RejectedExecutionException =>
throw Incomplete(None, message = Some("cancelled"))
}
() => future.get()
}