aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2019-12-08 13:40:57 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2019-12-08 13:40:57 +0300
commitc8749e6f6bf8f39a94791526b39fadc11360476c (patch)
treee6a8cfff3afe8750b5452a31755060f07eb99502 /README.md
Initial
Diffstat (limited to 'README.md')
-rw-r--r--README.md45
1 files changed, 45 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..df1e04f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,45 @@
+# Workflow for Go
+
+Simple state machine. Inspired by [Symfony Workflow](https://github.com/symfony/workflow).
+
+## Example usage
+
+```go
+o := new(ObjectImplementedPlaceer)
+
+w := NewWorkflow("initial")
+w.AddTransition("From initial to A", []Place{"initial"}, "A")
+w.AddTransition("From initial to B", []Place{"initial"}, "B")
+w.AddTransition("From A to C", []Place{"A"}, "C")
+w.AddTransition("From B,C to D", []Place{"B", "C"}, "D")
+w.AddTransition("From C,D to Finish", []Place{"C", "D"}, "Finish")
+
+w.Can(o, "From initial to A") // == nil
+w.Can(o, "From A to C") // == ErrCantApply
+
+w.GetEnabledTransitions(o) // []string{"From initial to A", "From initial to B"}
+w.Apply(o, "From inital to A") // o now at "A" place
+w.GetEnabledTransitions(o) // []string{"From A to C"}
+
+w.DumpToDot() // See above
+```
+
+## Dump result
+
+```
+digraph {
+ initial[color="blue"];
+ initial -> A[label="From initial to A"];
+ initial -> B[label="From initial to B"];
+ A -> C[label="From A to C"];
+ B -> D[label="From B,C to D"];
+ C -> D[label="From B,C to D"];
+ C -> Finish[label="From C,D to Finish"];
+ D -> Finish[label="From C,D to Finish"];
+}
+```
+
+Visualization:
+
+![Workflow visualization](images/example.png)
+