Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambdas as Callable hang REPL #10064

Closed
scabug opened this issue Nov 16, 2016 · 3 comments
Closed

Lambdas as Callable hang REPL #10064

scabug opened this issue Nov 16, 2016 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented Nov 16, 2016

Submitting a lambda as a callable and retrieving the future on the same line causes the REPL to hang.

Welcome to Scala 2.12.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
Type in expressions for evaluation. Or try :help.

scala> import java.util.concurrent._
import java.util.concurrent._

scala> val exec = Executors.newCachedThreadPool
exec: java.util.concurrent.ExecutorService = java.util.concurrent.ThreadPoolExecutor@7512870b[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]

OK, because not a lambda:

scala> exec.submit(new Callable[String] { def call = "foo" }).get
res0: String = foo

OK, because retrieval separate from submission:

scala> val f = exec.submit(() => "foo")
f: java.util.concurrent.Future[String] = java.util.concurrent.FutureTask@2c81f298

scala> f.get
res1: String = foo

Hangs:

scala> exec.submit(() => "foo").get

This was discovered in the real world by attempting scalaz.concurrent.Task("foo").run, which also hangs.

The same snippets all complete successfully on Scala 2.11.8.

Maybe related to SI-9076?

@scabug
Copy link
Author

scabug commented Nov 16, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10064?orig=1
Reporter: Ross A. Baker (rossabaker2)
Affected Versions: 2.12.0
See #9076

@scabug
Copy link
Author

scabug commented Nov 16, 2016

@retronym said:
Yes, this is the same issue. We need to change the way the REPL wraps the expressions to fix this.

@scabug scabug closed this as completed Nov 16, 2016
@scabug
Copy link
Author

scabug commented Nov 16, 2016

@som-snytt said:
Workaround and confirming that it is as linked:

$ scala -Yrepl-class-based
Welcome to Scala 2.12.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> import java.util.concurrent._
import java.util.concurrent._

scala> val exec = Executors.newCachedThreadPool
exec: java.util.concurrent.ExecutorService = java.util.concurrent.ThreadPoolExecutor@3ac8cf9b[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]

scala> exec.submit(() => "foo").get
res0: String = foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants