Skip to content

Commit

Permalink
Better README (#3)
Browse files Browse the repository at this point in the history
* Better README
  • Loading branch information
Jean-François Bustarret authored Oct 12, 2021
1 parent b0f4c04 commit 5fa3d57
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Finite State Machines [![PkgGoDev](https://pkg.go.dev/badge/github.com/cocoonspace/fsm)](https://pkg.go.dev/github.com/cocoonspace/fsm) [![Build Status](https://app.travis-ci.com/cocoonspace/fsm.svg?branch=master)](https://app.travis-ci.com/cocoonspace/fsm) [![Coverage Status](https://coveralls.io/repos/github/cocoonspace/fsm/badge.svg?branch=master)](https://coveralls.io/github/cocoonspace/fsm?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/cocoonspace/fsm)](https://goreportcard.com/report/github.com/cocoonspace/fsm)
# fsm [![PkgGoDev](https://pkg.go.dev/badge/github.com/cocoonspace/fsm)](https://pkg.go.dev/github.com/cocoonspace/fsm) [![Build Status](https://app.travis-ci.com/cocoonspace/fsm.svg?branch=master)](https://app.travis-ci.com/cocoonspace/fsm) [![Coverage Status](https://coveralls.io/repos/github/cocoonspace/fsm/badge.svg?branch=master)](https://coveralls.io/github/cocoonspace/fsm?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/cocoonspace/fsm)](https://goreportcard.com/report/github.com/cocoonspace/fsm)

Package fsm allows you to add [finite-state machines](https://en.wikipedia.org/wiki/Finite-state_machine) to your Go code.

Package fsm allows you to add Finite State Machines to your code.
States and Events are defined as int consts :

```go
const (
Expand All @@ -11,6 +12,7 @@ const (

const (
EventFoo fsm.Event = iota
EventBar
)

f := fsm.New(StateFoo)
Expand All @@ -24,11 +26,35 @@ You can have custom checks or actions :

```go
f.Transition(
fsm.Src(StateFoo), fsm.Check(func() bool {
fsm.Src(StateFoo), fsm.Check(func () bool {
// check something
}),
fsm.Call(func() {
fsm.Call(func () {
// do something
}),
)
```
```

Transitions can be triggered the second time an event occurs :

```go
f.Transition(
fsm.On(EventFoo), fsm.Src(StateFoo), fsm.Times(2),
fsm.Dst(StateBar),
)
```

## Installation

go get github.com/cocoonspace/fsm

## Contribution guidelines

Contributions are welcome, as long as:

* unit tests & comments are included,
* no external package is used.

## License

MIT - See LICENSE

0 comments on commit 5fa3d57

Please sign in to comment.