gocardless / statesman

A statesmanlike state machine library.
https://gocardless.com/blog/statesman/
MIT License
1.78k stars 163 forks source link

are state machines composable? #303

Closed BrianHicks closed 6 years ago

BrianHicks commented 6 years ago

I’m looking at statesman for a project. In this, we have a larger state machine comprised of several smaller state machines that get composed together in different ways.

How would you recommend I approach this? Is statesman an appropriate tool here?

danwakefield commented 6 years ago

Hi @BrianHicks

It would really helpful if you gave more context / some examples of the issue's you are having.

Since Statesman's state machines are independant classes there is no reason that you cannot use more than one together.

For example, If you had a class to represent a visit to a restaurant it could contain separate machines for different courses. The Main Course state machine could be blocked from moving to Dessert before the until it had been eaten and the plates cleared. And none of the Machines related to Food would prevent more drinks being ordered.

A rough sketch would be

Ordered -> Starter -> Main -> Dessert
              |
              V
           preparing
              |
              V
            cooked
              |
              V
          delivered
              |
              V
            eaten
              |
              V
        plate removed
BrianHicks commented 6 years ago

ah, that makes sense and answers my question. Thank you!