Implement new fsm
This commit is contained in:
41
internal/torrent/states.go
Normal file
41
internal/torrent/states.go
Normal 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{},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user