Skip to content

Commit 5a95105

Browse files
committed
Fix deadlock on quit
1 parent 048be13 commit 5a95105

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/main/ChildModel.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package org.nlogo.ls
33
import org.nlogo.api.{CommandRunnable, Workspace}
44
import org.nlogo.workspace.AbstractWorkspaceScala
55
import scala.collection.JavaConverters._
6+
import scala.concurrent.ExecutionContext.Implicits.global
7+
import scala.concurrent.Future
68
import javax.swing.{JFrame, SwingUtilities}
79

810
abstract class ChildModel(val parentWorkspace: Workspace, val modelID: Int) {
@@ -24,13 +26,14 @@ abstract class ChildModel(val parentWorkspace: Workspace, val modelID: Int) {
2426
}
2527

2628
def kill = {
27-
UnlockAndBlock(parentWorkspace.world) {
29+
Future {
2830
workspace.dispose
2931
}
30-
parentWorkspace waitFor new CommandRunnable {
31-
def run() = {
32-
frame.foreach(_.dispose)
33-
}
32+
val disposeRunnable = new CommandRunnable { def run() = frame.foreach(_.dispose) }
33+
if (java.awt.EventQueue.isDispatchThread()) {
34+
disposeRunnable.run
35+
} else {
36+
parentWorkspace.waitFor(disposeRunnable)
3437
}
3538
}
3639

0 commit comments

Comments
 (0)