mirror of
https://github.com/sbt/sbt.git
synced 2026-08-22 06:07:24 +02:00
local SyncVar implementation to deal with std lib deprecations
This commit is contained in:
@@ -9,8 +9,6 @@ import java.io.{FilterInputStream, FilterOutputStream, PipedInputStream, PipedOu
|
|||||||
import java.io.{File, FileInputStream, FileOutputStream}
|
import java.io.{File, FileInputStream, FileOutputStream}
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
import scala.concurrent.SyncVar
|
|
||||||
|
|
||||||
/** Runs provided code in a new Thread and returns the Thread instance. */
|
/** Runs provided code in a new Thread and returns the Thread instance. */
|
||||||
private object Spawn
|
private object Spawn
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package sbt
|
||||||
|
|
||||||
|
// minimal copy of scala.concurrent.SyncVar since that version deprecated put and unset
|
||||||
|
private[sbt] final class SyncVar[A]
|
||||||
|
{
|
||||||
|
private[this] var isDefined: Boolean = false
|
||||||
|
private[this] var value: Option[A] = None
|
||||||
|
|
||||||
|
/** Waits until a value is set and then gets it. Does not clear the value */
|
||||||
|
def get: A = synchronized {
|
||||||
|
while (!isDefined) wait()
|
||||||
|
value.get
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Waits until a value is set, gets it, and finally clears the value. */
|
||||||
|
def take(): A = synchronized {
|
||||||
|
try get finally unset()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the value, whether or not it is currently defined. */
|
||||||
|
def set(x: A): Unit = synchronized {
|
||||||
|
isDefined = true
|
||||||
|
value = Some(x)
|
||||||
|
notifyAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the value, first waiting until it is undefined if it is currently defined. */
|
||||||
|
def put(x: A): Unit = synchronized {
|
||||||
|
while (isDefined) wait()
|
||||||
|
set(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clears the value, whether or not it is current defined. */
|
||||||
|
def unset(): Unit = synchronized {
|
||||||
|
isDefined = false
|
||||||
|
value = None
|
||||||
|
notifyAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user