mirror of https://github.com/sbt/sbt.git
Throw timeoutexception in JoinThread
Rather than throwing an interrupted exception if we fail to join a thread, we should throw a timeout exception.
This commit is contained in:
parent
e5164cdf43
commit
748dfd6e67
|
|
@ -9,23 +9,22 @@ package sbt.internal.util
|
|||
|
||||
import scala.annotation.tailrec
|
||||
import scala.concurrent.duration._
|
||||
import java.util.concurrent.TimeoutException
|
||||
|
||||
object JoinThread {
|
||||
implicit class ThreadOps(val t: Thread) extends AnyVal {
|
||||
def joinFor(duration: FiniteDuration): Unit = {
|
||||
val deadline = duration.fromNow
|
||||
var exception: Option[InterruptedException] = None
|
||||
@tailrec def impl(): Unit = {
|
||||
try {
|
||||
t.interrupt()
|
||||
t.join(10)
|
||||
} catch { case e: InterruptedException => exception = Some(e) }
|
||||
} catch { case e: InterruptedException => }
|
||||
if (t.isAlive && !deadline.isOverdue) impl()
|
||||
}
|
||||
impl()
|
||||
if (t.isAlive) {
|
||||
System.err.println(s"Unable to join thread $t after $duration")
|
||||
exception.foreach(throw _)
|
||||
throw new TimeoutException(s"Unable to join thread $t after $duration")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue