Files
zurg/internal/torrent/states.go
Ben Sarmiento 4ec1c4496d Optimizations
2024-05-27 10:18:51 +02:00

30 lines
820 B
Go

package torrent
import (
"github.com/looplab/fsm"
)
func NewTorrentState(initial string) *fsm.FSM {
return fsm.NewFSM(
initial,
fsm.Events{
{Name: "break_torrent", Src: []string{"ok_torrent"}, Dst: "broken_torrent"},
{Name: "repair_torrent", Src: []string{"ok_torrent", "broken_torrent"}, Dst: "under_repair_torrent"},
{Name: "mark_as_repaired", Src: []string{"broken_torrent", "under_repair_torrent"}, Dst: "ok_torrent"},
},
fsm.Callbacks{},
)
}
func NewFileState(initial string) *fsm.FSM {
return fsm.NewFSM(
initial,
fsm.Events{
{Name: "break_file", Src: []string{"ok_file"}, Dst: "broken_file"},
{Name: "repair_file", Src: []string{"broken_file"}, Dst: "ok_file"},
{Name: "delete_file", Src: []string{"ok_file", "broken_file"}, Dst: "deleted_file"},
},
fsm.Callbacks{},
)
}