feat: 完善并发型状态机.

This commit is contained in:
2025-02-06 15:28:14 +08:00
parent 52946be558
commit 3a4db562ce
3 changed files with 108 additions and 11 deletions

View File

@@ -48,4 +48,18 @@ public class MachineTest {
stateMachine.close();
}
@Test
public void testConcurrentStateMachine() throws Exception {
ConcurrentStateMachine<PrinterState> stateMachine = StateMachineBuilder.from(PrinterState.values())
.whenEntry(PrinterState.STOPPING, h -> {
System.out.println(1111);
})
.concurrent()
.build();
System.out.println(stateMachine.compareAndSet(PrinterState.IDLE, PrinterState.STOPPING, true));
stateMachine.close();
}
}