spring-statemachine icon indicating copy to clipboard operation
spring-statemachine copied to clipboard

Why isn't the actionFunction working properly?

Open aohanhe opened this issue 5 months ago • 1 comments

`.actionFunction(context -> { Flux<String> businessFlux = Flux.just("A", "B", "C") .delayElements(Duration.ofMillis(1000)) .map(item -> { if ("B".equals(item)) { RuntimeException err = new RuntimeException("test one error");

              throw err;
            }
            return item;
          });

      return businessFlux.then();
    })`

The result of stateMachine.sendEvent is always ACCEPTED. Why is this happening and how can I handle it?

aohanhe avatar Jul 23 '25 13:07 aohanhe

Changing the code to the following method still fails to intercept the state changes of the state machine through exceptions. `.actionFunction(context -> { return Mono.just("") // 切换到弹性线程池执行阻塞操作 .subscribeOn(Schedulers.boundedElastic()) .flatMap(__ -> { try { List<String> results = Flux.just("A", "B", "C") .delayElements(Duration.ofMillis(1000)) .map(item -> { if ("B".equals(item)) { throw new RuntimeException("test one error"); } return item; })
.collectList() .block();

              return Mono.empty();
            } catch (Exception e) {   
              return Mono.error(e);
            }
          });
    })`

aohanhe avatar Jul 23 '25 14:07 aohanhe