aboutsummaryrefslogblamecommitdiff
path: root/content/go/workflow.md
blob: 9b846bf90a7a259b07efd96405608aefda0cdf17 (plain) (tree)
1
2
3
4
5
6
7
8
9




                                                                        

                  

   







































                                                                                          
+++
title = "Workflow"
name = "workflow"
repository = "https://git.neonxp.ru/workflow.git"
description = "Простой конечный автомат для Go"
gomod = true
outputs = ["html"]
+++

Simple state machine. Inspired by [Symfony Workflow](https://github.com/symfony/workflow).

## Example usage

```go
o := new(ObjectImplementedPlaceer)

w := NewWorkflow("Start")
w.AddTransition("Start", "A")
w.AddTransition("Start", "B")
w.AddTransition("A", "C")
w.AddTransition("B",  "D")
w.AddTransition( "C", "D")
w.AddTransition("C", "Finish")
w.AddTransition("D", "Finish")

w.Can(o, "A") // == nil
w.Can(o, "C") // == ErrTransitionNotFound

w.GetEnabledTransitions(o) // []Place{"A", "B"}
w.Apply(o, "A") // o now at "A" place
w.GetEnabledTransitions(o) // []Place{"C"}

w.DumpToDot() // See above
```

## Dump result

```
digraph {
    Start[color="blue"]
    Start -> A[label="Start → A"];
    Start -> B[label="Start → B"];
    A -> C[label="A → C"];
    B -> D[label="B → D"];
    C -> D[label="C → D"];
    C -> Finish[label="C → Finish"];
    D -> Finish[label="D → Finish"];
}
```