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