work in progress: action handling
This commit is contained in:
parent
5e60c3e10b
commit
5c6a7c76d8
4 changed files with 51 additions and 5 deletions
|
@ -18,3 +18,43 @@ func (spec *baseSpec) Receivers() []string {
|
|||
func BaseSpec(hdlr lib.ActionHandler, rcvrs []string) *baseSpec {
|
||||
return &baseSpec{hdlr, rcvrs}
|
||||
}
|
||||
|
||||
// action selection
|
||||
|
||||
func Select(ctx lib.Context, msg lib.Message) []lib.Action {
|
||||
var acts []lib.Action
|
||||
// act := action{ctx, spec, msg}
|
||||
// acts = append(acts, &act)
|
||||
return acts
|
||||
}
|
||||
|
||||
// action
|
||||
|
||||
type action struct {
|
||||
ctx lib.Context
|
||||
spec lib.ActionSpec
|
||||
msg lib.Message
|
||||
}
|
||||
|
||||
func (act *action) Context() lib.Context {
|
||||
return act.ctx
|
||||
}
|
||||
|
||||
func (act *action) Spec() lib.ActionSpec {
|
||||
return act.spec
|
||||
}
|
||||
|
||||
func (act *action) Message() lib.Message {
|
||||
return act.msg
|
||||
}
|
||||
|
||||
func (act *action) Handle() bool {
|
||||
return act.spec.Handler()(act)
|
||||
}
|
||||
|
||||
// predefined action handlers
|
||||
|
||||
func Forward(act lib.Action) bool {
|
||||
// Send(ctx, addr. msg)
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"git.sr.ht/~cco/go-scopes/lib"
|
||||
"git.sr.ht/~cco/go-scopes/lib/action"
|
||||
)
|
||||
|
||||
func Start(ctx lib.Context) {
|
||||
|
@ -29,7 +30,12 @@ func Step(ctx lib.Context) (loop bool) {
|
|||
return
|
||||
}
|
||||
|
||||
func HandleMessage(ctx lib.Context, msg lib.Message) bool {
|
||||
fmt.Println("HandleMessage", msg)
|
||||
return true
|
||||
func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) {
|
||||
loop = true
|
||||
fmt.Println("core.HandleMessage", msg)
|
||||
for _, act := range action.Select(ctx, msg) {
|
||||
//loop = act.Spec().Handler()(act)
|
||||
loop = act.Handle()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ type Action interface {
|
|||
Context() Context
|
||||
Spec() ActionSpec
|
||||
Message() Message
|
||||
Handle() bool
|
||||
}
|
||||
|
||||
type Proc = func(Context)
|
||||
|
|
|
@ -27,8 +27,7 @@ func Config() lib.Config {
|
|||
return &cfg
|
||||
}
|
||||
|
||||
// register action handlers from ..._test.go here:
|
||||
|
||||
// register action handlers from ..._test.go here.
|
||||
var (
|
||||
AH_Receiver lib.ActionHandler
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue