summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-06-20 16:55:48 +0000
committerPaul Phillips <paulp@improving.org>2009-06-20 16:55:48 +0000
commit8cf7228f8c1e11d67f4b7053b4ff2772e2bd79fc (patch)
tree0517282d9e1beb8330a694617504795d6ae2f6c4 /src
parent533764a7180c005024e997246a56ee9fce337bb5 (diff)
downloadscala-8cf7228f8c1e11d67f4b7053b4ff2772e2bd79fc.tar.gz
scala-8cf7228f8c1e11d67f4b7053b4ff2772e2bd79fc.tar.bz2
scala-8cf7228f8c1e11d67f4b7053b4ff2772e2bd79fc.zip
Created DelayedLazyVal for your def/val hybrid ...
Created DelayedLazyVal for your def/val hybrid needs.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Completion.scala16
-rw-r--r--src/dotnet-library/scala/concurrent/DelayedLazyVal.scala1
-rw-r--r--src/library/scala/concurrent/DelayedLazyVal.scala44
3 files changed, 47 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/Completion.scala b/src/compiler/scala/tools/nsc/interpreter/Completion.scala
index 2239f7cc3a..599ad8fa18 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Completion.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Completion.scala
@@ -24,6 +24,7 @@ package scala.tools.nsc.interpreter
import jline._
import java.net.URL
import java.util.concurrent.ConcurrentHashMap
+import scala.concurrent.DelayedLazyVal
// REPL completor - queries supplied interpreter for valid completions
// based on current contents of buffer.
@@ -32,23 +33,10 @@ class Completion(val interpreter: Interpreter) extends Completor {
import java.util.{ List => JList }
import interpreter.compilerClasspath
- // This is a wrapper which lets us use a def until some lengthy
- // action is complete, and then a val from that point on.
- class LazyValFuture[T](f: () => T, body: => Unit) {
- private[this] var isDone = false
- private[this] lazy val complete = f()
- def apply(): T = if (isDone) complete else f()
-
- scala.concurrent.ops.future {
- body
- isDone = true
- }
- }
-
// it takes a little while to look through the jars so we use a future and a concurrent map
class CompletionAgent {
val dottedPaths = new ConcurrentHashMap[String, List[String]]
- val topLevelPackages = new LazyValFuture(
+ val topLevelPackages = new DelayedLazyVal(
() => enumToList(dottedPaths.keys) filterNot (_ contains '.'),
getDottedPaths(dottedPaths, interpreter)
)
diff --git a/src/dotnet-library/scala/concurrent/DelayedLazyVal.scala b/src/dotnet-library/scala/concurrent/DelayedLazyVal.scala
new file mode 100644
index 0000000000..66ec24f8eb
--- /dev/null
+++ b/src/dotnet-library/scala/concurrent/DelayedLazyVal.scala
@@ -0,0 +1 @@
+/* DelayedLazyVal does not exist for the dotnet target */
diff --git a/src/library/scala/concurrent/DelayedLazyVal.scala b/src/library/scala/concurrent/DelayedLazyVal.scala
new file mode 100644
index 0000000000..0fa3c1660b
--- /dev/null
+++ b/src/library/scala/concurrent/DelayedLazyVal.scala
@@ -0,0 +1,44 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.concurrent
+
+import annotation.experimental
+
+/** A <code>DelayedLazyVal</code> is a wrapper for lengthy
+ * computations which have a valid partially computed result.
+ * The first argument is a function for obtaining the result
+ * at any given point in time, and the second is the lengthy
+ * computation. Once the computation is complete, the apply()
+ * method will stop recalculating it and return a fixed value
+ * from that point forward.
+ *
+ * @param f the function to obtain the current value at any point in time
+ * @param body the computation to run to completion in another thread
+ *
+ * @author Paul Phillips
+ * @version 2.8
+ */
+@experimental
+class DelayedLazyVal[T](f: () => T, body: => Unit) {
+ @volatile private[this] var isDone = false
+ private[this] lazy val complete = f()
+
+ /** The current result of f(), or the final result if complete.
+ *
+ * @return the current value
+ */
+ def apply(): T = if (isDone) complete else f()
+
+ ops.future {
+ body
+ isDone = true
+ }
+} \ No newline at end of file