
sbt.internal.util.JoinThread.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of command_2.12 Show documentation
Show all versions of command_2.12 Show documentation
sbt is an interactive build tool
The newest version!
/*
* sbt
* Copyright 2023, Scala center
* Copyright 2011 - 2022, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
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
@tailrec def impl(): Unit = {
try {
t.interrupt()
t.join(10)
} catch { case e: InterruptedException => }
if (t.isAlive && !deadline.isOverdue()) impl()
}
impl()
if (t.isAlive) {
throw new TimeoutException(s"Unable to join thread $t after $duration")
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy