appccelerate / statemachine

A .net library that lets you build state machines (hierarchical, async with fluent definition syntax and reporting capabilities).
Apache License 2.0
488 stars 128 forks source link

Events fire with ref or out may not be passed #66

Closed muisje closed 4 years ago

muisje commented 4 years ago

Hey,

I was implementing a function that executes an event in which i want to have a variable set for the caller to read. I need this because i need to know which state i'm in outside of the state machine.

So if i could fire an event with a return value or with a ref/ out parameter that would be nice :)

muisje commented 4 years ago

I solved this with having context object as argument and setting member values inside the function called and reading it after the the event is fired with a getter for the set property.

I do think using out would have been a nicer solution though.

ursenzler commented 4 years ago

Glad that you found a solution.

I consider exposing the state the state-machine is in an anti-pattern. The reasoning is, that while the state-machine is executing a non-empty queue of events - especially an active state-machine - it is hard to say in which state the machine really is.

I normally advise using some flags on the containing class that reflect the states that you want to expose to the environment of the state-machine.