Implement new fsm

This commit is contained in:
Ben Sarmiento
2024-05-21 01:59:53 +02:00
parent d5dd9426ed
commit 2c5e7a1db0
14 changed files with 121 additions and 59 deletions

View File

@@ -0,0 +1,41 @@
package torrent
import (
"github.com/looplab/fsm"
)
func NewTorrentState(initial string) *fsm.FSM {
// ok
// broken
// under_repair
// deleted
// unplayable
return fsm.NewFSM(
initial,
fsm.Events{
{Name: "break", Src: []string{"ok", "unplayable"}, Dst: "broken"},
{Name: "repair", Src: []string{"broken"}, Dst: "under_repair"},
{Name: "repair_done", Src: []string{"under_repair"}, Dst: "ok"},
{Name: "delete", Src: []string{"ok", "broken", "under_repair", "unplayable"}, Dst: "deleted"},
{Name: "mark_as_unplayable", Src: []string{"ok", "under_repair"}, Dst: "unplayable"},
},
fsm.Callbacks{},
)
}
func NewFileState(initial string) *fsm.FSM {
// ok
// broken
// under_repair
// deleted
return fsm.NewFSM(
initial,
fsm.Events{
{Name: "break", Src: []string{"ok"}, Dst: "broken"},
{Name: "repair", Src: []string{"broken"}, Dst: "under_repair"},
{Name: "repair_done", Src: []string{"under_repair"}, Dst: "ok"},
{Name: "delete", Src: []string{"ok", "broken", "under_repair"}, Dst: "deleted"},
},
fsm.Callbacks{},
)
}