RuffyScripter: wait for command thread to finish up.

This commit is contained in:
Johannes Mockenhaupt 2017-12-06 16:06:16 +01:00
parent 51b51c159c
commit 1cbfefffb8
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -231,12 +231,13 @@ public class RuffyScripter implements RuffyCommands {
} }
synchronized (RuffyScripter.class) { synchronized (RuffyScripter.class) {
Thread cmdThread = null;
try { try {
activeCmd = cmd; activeCmd = cmd;
long connectStart = System.currentTimeMillis(); long connectStart = System.currentTimeMillis();
ensureConnected(); ensureConnected();
log.debug("Connection ready to execute cmd " + cmd); log.debug("Connection ready to execute cmd " + cmd);
Thread cmdThread = new Thread(() -> { cmdThread = new Thread(() -> {
try { try {
if (!runPreCommandChecks(cmd)) { if (!runPreCommandChecks(cmd)) {
return; return;
@ -323,6 +324,14 @@ public class RuffyScripter implements RuffyCommands {
if (activeCmd.getResult().success && menu != null && menu.getType() != MenuType.MAIN_MENU) { if (activeCmd.getResult().success && menu != null && menu.getType() != MenuType.MAIN_MENU) {
log.warn("Command " + activeCmd + " successful, but finished leaving pump on menu " + getCurrentMenuName()); log.warn("Command " + activeCmd + " successful, but finished leaving pump on menu " + getCurrentMenuName());
} }
if (cmdThread != null) {
try {
// let command thread finish updating activeCmd var
cmdThread.join(1000);
} catch (InterruptedException e) {
// ignore
}
}
activeCmd = null; activeCmd = null;
} }
} }