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) {
Thread cmdThread = null;
try {
activeCmd = cmd;
long connectStart = System.currentTimeMillis();
ensureConnected();
log.debug("Connection ready to execute cmd " + cmd);
Thread cmdThread = new Thread(() -> {
cmdThread = new Thread(() -> {
try {
if (!runPreCommandChecks(cmd)) {
return;
@ -323,6 +324,14 @@ public class RuffyScripter implements RuffyCommands {
if (activeCmd.getResult().success && menu != null && menu.getType() != MenuType.MAIN_MENU) {
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;
}
}