@@ -64,7 +64,7 @@ object Worksheet {
64
64
private def execute (evaluator : Evaluator , tree : Tree , sourcefile : SourceFile ): (Int , String ) = {
65
65
val source = sourcefile.content.slice(tree.pos.start, tree.pos.end).mkString
66
66
val line = sourcefile.offsetToLine(tree.pos.end)
67
- (line, evaluator.eval(source))
67
+ (line, evaluator.eval(source).getOrElse( " " ) )
68
68
}
69
69
70
70
private def encode (message : String , line : Int ): String =
@@ -155,10 +155,10 @@ private class Evaluator private (javaExec: String,
155
155
* @param command The command to evaluate.
156
156
* @return The result from the REPL.
157
157
*/
158
- def eval (command : String ): String = {
158
+ def eval (command : String ): Option [ String ] = {
159
159
processInput.println(command)
160
160
processInput.flush()
161
- processOutput.next().trim
161
+ processOutput.next().map(_. trim)
162
162
}
163
163
164
164
/**
@@ -212,6 +212,7 @@ private class ReplReader(stream: InputStream) extends Thread {
212
212
private val in = new InputStreamReader (stream)
213
213
214
214
private [this ] var output : Option [String ] = None
215
+ private [this ] var closed : Boolean = false
215
216
216
217
override def run (): Unit = synchronized {
217
218
val prompt = " scala> "
@@ -228,18 +229,18 @@ private class ReplReader(stream: InputStream) extends Thread {
228
229
wait()
229
230
}
230
231
}
231
- output = Some ( " " )
232
+ closed = true
232
233
notify()
233
234
}
234
235
235
236
/** Block until the next message is ready. */
236
- def next (): String = synchronized {
237
+ def next (): Option [ String ] = synchronized {
237
238
238
- while (output.isEmpty) {
239
+ while (! closed && output.isEmpty) {
239
240
wait()
240
241
}
241
242
242
- val result = output.get
243
+ val result = output
243
244
notify()
244
245
output = None
245
246
result
0 commit comments