This commit is contained in:
Imbus 2024-11-07 22:25:54 +01:00
parent 2eeb21c5ce
commit 22410c419f

View file

@ -20,17 +20,19 @@ public class Wash {
water.start();
spin.start();
ActorThread<WashingMessage> t = null;
// Instantiated to avoid nullchecking in the interrupt inside the loop
ActorThread<WashingMessage> t = new EmptyProgram();
outer: while (true) {
int n = io.awaitButton();
t.interrupt(); // Immediately abort previous action, t != null here
System.out.println("user selected program " + n);
// if the user presses buttons 1-3, start a washing program
// if the user presses button 0, and a program has been started, stop it
switch (n) {
case 0 -> t = new WashingProgramN(io, temp, water, spin);
case 0 -> t = new WashingProgramStop(io, temp, water, spin);
case 1 -> t = new WashingProgram1(io, temp, water, spin);
case 2 -> t = new WashingProgram2(io, temp, water, spin);
case 3 -> t = new WashingProgram3(io, temp, water, spin);