diff --git a/config/config.go b/config/config.go index 9ac9b97..cbf001f 100644 --- a/config/config.go +++ b/config/config.go @@ -75,11 +75,10 @@ func (cfg *Base) WithMessageHandler(hdlr lib.MessageHandler) *Base { return cfg } -func (cfg *Base) WithAction(pattern string, spec lib.ActionSpec) lib.Config { +func (cfg *Base) AddAction(pattern string, spec lib.ActionSpec) { act := ActionConfig(pattern, nil) act.specs = append(act.specs, spec) cfg.actions = append(cfg.actions, act) - return cfg } func MakeBase(name string, starter lib.StartProc) *Base { diff --git a/lib/action/action.go b/lib/action/action.go index cd0392d..a2efcf7 100644 --- a/lib/action/action.go +++ b/lib/action/action.go @@ -73,7 +73,7 @@ func Forward(act lib.Action) bool { msg := act.Message() for _, rcvr := range act.Spec().Receivers() { addr := message.SimpleAddress(rcvr) - message.Send(ctx, addr, msg) + lib.Send(ctx, addr, msg) } return true } diff --git a/lib/lib.go b/lib/lib.go index 98d55f1..1ad6241 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -25,7 +25,7 @@ type Config interface { Actions() []ActionConfig Children() []Config Add(Config) - WithAction(string, ActionSpec) Config + AddAction(string, ActionSpec) } type Services map[string]Context @@ -69,7 +69,7 @@ type StepProc = func(Context) bool type MessageHandler = func(Context, Message) bool type ActionHandler = func(Action) bool -// async Runners +// library functions func RunCtx(ctx Context, fct Proc) { ctx.WaitGroup().Add(1) @@ -78,3 +78,9 @@ func RunCtx(ctx Context, fct Proc) { fct(ctx) }() } + +func Send(ctx Context, addr Address, msg Message) { + if srv, ok := ctx.Services()[addr.Service()]; ok { + srv.Mailbox() <- msg + } +} diff --git a/lib/message/message.go b/lib/message/message.go index be5c11d..2650eaf 100644 --- a/lib/message/message.go +++ b/lib/message/message.go @@ -31,7 +31,7 @@ func (addr *address) Service() string { } func (addr *address) Send(ctx lib.Context, msg lib.Message) { - Send(ctx, addr, msg) + lib.Send(ctx, addr, msg) } func SimpleAddress(srv string) *address { @@ -39,11 +39,3 @@ func SimpleAddress(srv string) *address { service: srv, } } - -// public functions - -func Send(ctx lib.Context, addr lib.Address, msg lib.Message) { - if srv, ok := ctx.Services()[addr.Service()]; ok { - srv.Mailbox() <- msg - } -} diff --git a/tests/etc/etc.go b/tests/etc/etc.go index 19ae1e1..3d119ee 100644 --- a/tests/etc/etc.go +++ b/tests/etc/etc.go @@ -12,20 +12,26 @@ import ( func Config() lib.Config { ovr := Overrides().Use b := config.MakeBase + cfg := app.Cfg{ - Base: b("testing", testing.Start). - WithAction("demo", - action.BaseSpec(action.Forward, - []string{"test-receiver"})).(*config.Base), + Base: b("testing", testing.Start), Home: ovr(".", HOME), AppType: "standard", } - cfg.Add(config.Cfg{ + cfg.AddAction("demo", + action.BaseSpec(action.Forward, + []string{"test-receiver"})) + + cfg_config := config.Cfg{ Base: b("config", config.Start), ConfigFormat: "etc", - }) - cfg.Add(b("test-receiver", core.Start). - WithAction("*", action.BaseSpec(AH_Receiver, nil))) + } + cfg.Add(cfg_config) + + cfg_test_rcvr := b("test-receiver", core.Start) + cfg_test_rcvr.AddAction("*", action.BaseSpec(AH_Receiver, nil)) + cfg.Add(cfg_test_rcvr) + return &cfg } diff --git a/tests/scopes_test.go b/tests/scopes_test.go index 1a83798..7c2fa92 100644 --- a/tests/scopes_test.go +++ b/tests/scopes_test.go @@ -36,9 +36,9 @@ func SendTest(t *testing.T) { ctx := t.Ctx rcvr := message.SimpleAddress("testing") msg := message.StrMessage("demo") - rcvr.Send(ctx, msg) + lib.Send(ctx, rcvr, msg) rcvr = message.SimpleAddress("test-receiver") - rcvr.Send(ctx, msg) + lib.Send(ctx, rcvr, msg) } // action handlers