Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive Api for doWithAllRegions #1116

Open
bhishambajaj1999 opened this issue Oct 1, 2023 · 1 comment
Open

Reactive Api for doWithAllRegions #1116

bhishambajaj1999 opened this issue Oct 1, 2023 · 1 comment
Labels
status/need-triage Team needs to triage and take a first look

Comments

@bhishambajaj1999
Copy link

The current doWithAllRegion method doesn't support non reactive api.
void doWithAllRegions(Consumer<StateMachineAccess<S, E>> stateMachineAccess);
I am using 3.0.1 version of spring state machine.
To Restart the stateMachineReactively I have to use subscribe() which is not preferred.
Please find the snippet

public Mono<StateMachine<OrderState, OrderEvent>> returnActivatedStateMachine(
OrderState orderState,
StateMachine<OrderState, OrderEvent> stateMachine) {

return stateMachine.stopReactively()
    .then(Mono.defer(() -> {
          StateMachineContext<OrderState, OrderEvent> context = new DefaultStateMachineContext<>(
              orderState, null, null, null);

          stateMachine.getStateMachineAccessor()
              .doWithAllRegions(access -> access.resetStateMachineReactively(context).subscribe());

          return stateMachine.startReactively();
        })
        .thenReturn(stateMachine));

}

Can you please help with some reactive alternate for doWithAllRegions?

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Oct 1, 2023
@kzander91
Copy link

You could collect the Monos into a list like this:

List<Mono<Void>> monos = new ArrayList<>();
stateMachine.getStateMachineAccessor()
  .doWithAllRegions(access -> monos.add(access.resetStateMachineReactively(context)));
Mono.when(monos).thenEmpty(stateMachine.startReactively());

But I agree it's not that ideal...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-triage Team needs to triage and take a first look
Projects
None yet
Development

No branches or pull requests

2 participants