dotnet-state-machine / stateless

A simple library for creating state machines in C# code
Other
5.53k stars 765 forks source link

[Questions] Queue implementation? #556

Closed LiorBanai closed 7 months ago

LiorBanai commented 9 months ago

Hi, I plan to start using this library (seems awesome and meet to my needs).

I was wondering how it handles fast triggers or multiple same trigger. let say I have 2 events: start and stop recording. Moving from idle state to recording state takes x amount of time.

What would happen if 2 fast start recording events will come? will those be queued and the second one will applied after end of processing the first one (and will be ignored since we are alreay in recording when processing that trigger/event takes place)?

mclift commented 9 months ago

Hi,

If your transitions are being invoked from a single thread then the default FiringMode configuration, FiringMode.Queued, should ensure that each trigger is executed to completion before the next one is executed. So in the scenario where the same trigger is fired a second time before the transition started by the first trigger has completed, the second trigger will be queued until the running transition completes.

Stateless isn't designed to be thread-safe, so if your triggers could be fired from multiple threads then you may want to consider marshalling those calls into a single thread.

HTH!

mclift commented 9 months ago

While I think about it, there's a discussion in issue #527 about concurrency that may be relevant to you.

LiorBanai commented 9 months ago

Thanks @mclift ! will integrate the library and see how to work with those conditions.