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

Race condition when ::rs/start is followed by ::rs/transition #3

Open
brjann opened this issue Dec 4, 2021 · 2 comments
Open

Race condition when ::rs/start is followed by ::rs/transition #3

brjann opened this issue Dec 4, 2021 · 2 comments

Comments

@brjann
Copy link

brjann commented Dec 4, 2021

I'm switching from kee-frame.fsm.alpha to re-statecharts and this far I really like the new library!

I think I have stumbled upon a race condition though. I cannot return this from an effect

{:dispatch-n [[::rs/start fsm]
              [::rs/transition (:id fsm) :some-event]]

The :some-event transition does not happen. I guess because rs/integrate does not start the fsm immediately but instead dispatches ::rs/init which will get executed after my call to ::rs/transition

@ingesolvoll
Copy link
Owner

Hm, that’s an interesting case. I think you could even say that theoretically the transition could happen before the start because re-frame doesn’t guarantee order? But I think your analysis is correct, start has not finished the things it needs to do before transition happens.

The immediate suggestion, without looking further into this, would be to either separate the 2 events, or just have the start state of the fsm be whatever some-event causes.

@brjann
Copy link
Author

brjann commented Dec 4, 2021

Thanks!

I think you could even say that theoretically the transition could happen before the start because re-frame doesn’t guarantee order?

Oh, I was pretty sure that events in dispatch-n are guaranteed order?

Edit: They are: https://day8.github.io/re-frame/api-builtin-effects/

have the start state of the fsm be whatever some-event causes.

Yes, that is actually what I did. For different reasons I would have liked to be able to dispatch like that, but your suggested method also works. I just wanted you to know of this potential race condition if it is not intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants