Introduce components

This commit is contained in:
Ben Sarmiento
2024-05-20 20:43:19 +02:00
parent ab81eb5f39
commit a3a24124a8
11 changed files with 222 additions and 202 deletions

31
internal/torrent/fsm.go Normal file
View File

@@ -0,0 +1,31 @@
package torrent
import (
"github.com/looplab/fsm"
)
func NewFileState() *fsm.FSM {
return fsm.NewFSM(
"ok",
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{},
)
}
func NewTorrentState() *fsm.FSM {
return fsm.NewFSM(
"ok",
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{},
)
}