Browse files

Allow nested calls to `askForResponse` in the presentation compiler.

Fix #6312.

review by @odersky,@lrytz.(cherry picked from commit 4f932df)
  • Loading branch information...
1 parent 0054b6c commit f2caa7717eb991f9973ec68d47c1cd969db6ea23 @dragos dragos committed Sep 4, 2012
View
16 src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
@@ -256,12 +256,18 @@ trait CompilerControl { self: Global =>
*/
def askForResponse[A](op: () => A): Response[A] = {
val r = new Response[A]
- val ir = scheduler askDoQuickly op
- ir onComplete {
- case Left(result) => r set result
- case Right(exc) => r raise exc
+ if (self.onCompilerThread) {
+ try { r set op() }
+ catch { case exc: Throwable => r raise exc }
+ r
+ } else {
+ val ir = scheduler askDoQuickly op
+ ir onComplete {
+ case Left(result) => r set result
+ case Right(exc) => r raise exc
+ }
+ r
}
- r
}
def onCompilerThread = Thread.currentThread == compileRunner
View
4 test/files/presentation/recursive-ask.check
@@ -0,0 +1,4 @@
+[ outer] askForResponse
+[nested] askForResponse
+passed
+done
View
20 test/files/presentation/recursive-ask/RecursiveAsk.scala
@@ -0,0 +1,20 @@
+import scala.tools.nsc.interactive.tests._
+
+object Test extends InteractiveTest {
+
+ override def main(args: Array[String]): Unit = {
+ val res0 = compiler.askForResponse( () => {
+ println("[ outer] askForResponse")
+ val res = compiler.askForResponse( () => { println("[nested] askForResponse") })
+ println (res.get(5000) match {
+ case Some(_) => "passed"
+ case None => "timeout"
+ })
+ })
+
+ res0.get(5000)
+
+ println("done")
+ compiler.askShutdown()
+ }
+}

0 comments on commit f2caa77

Please sign in to comment.