use special Quit message for stopping app; check Done channel
This commit is contained in:
parent
22e8759369
commit
35799f8d6c
4 changed files with 22 additions and 8 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"git.sr.ht/~cco/go-scopes/config"
|
||||
"git.sr.ht/~cco/go-scopes/lib"
|
||||
"git.sr.ht/~cco/go-scopes/lib/message"
|
||||
)
|
||||
|
||||
type Cfg struct {
|
||||
|
@ -41,13 +42,15 @@ func step(ctx lib.Context, sig <-chan os.Signal) bool {
|
|||
//ctx.LogInfo("Dispatcher interrupted", m.Map{})
|
||||
return false
|
||||
case msg := <-ctx.Mailbox():
|
||||
fmt.Println("message", msg)
|
||||
fmt.Println("app.step: message =", msg)
|
||||
//ctx.LogDebug("dispatcherStep", m.Map{"msg": msg})
|
||||
if msg.Action() == "quit" {
|
||||
if msg == message.Quit {
|
||||
//ctx.LogInfo("Dispatcher stopped", m.Map{})
|
||||
return false
|
||||
}
|
||||
return ctx.HandleMsg(msg)
|
||||
case <-ctx.Done():
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ type Base struct {
|
|||
children []lib.Config
|
||||
}
|
||||
|
||||
// lib.Config implementation
|
||||
|
||||
func (cfg *Base) Name() string {
|
||||
return cfg.name
|
||||
}
|
||||
|
@ -42,11 +44,6 @@ func (cfg *Base) MessageHandler() lib.MessageHandler {
|
|||
return cfg.msgHandler
|
||||
}
|
||||
|
||||
func (cfg *Base) WithMessageHandler(hdlr lib.MessageHandler) *Base {
|
||||
cfg.msgHandler = hdlr
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (cfg *Base) Actions() []lib.ActionConfig {
|
||||
return cfg.actions
|
||||
}
|
||||
|
@ -59,6 +56,18 @@ func (cfg *Base) Add(child lib.Config) {
|
|||
cfg.children = append(cfg.children, child)
|
||||
}
|
||||
|
||||
// implementation-specific methods and functions
|
||||
|
||||
func (cfg *Base) WithStep(step lib.StepProc) *Base {
|
||||
cfg.step = step
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (cfg *Base) WithMessageHandler(hdlr lib.MessageHandler) *Base {
|
||||
cfg.msgHandler = hdlr
|
||||
return cfg
|
||||
}
|
||||
|
||||
func MakeBase(name string, starter lib.StartProc) *Base {
|
||||
return &Base{
|
||||
name: name,
|
||||
|
|
|
@ -18,6 +18,8 @@ func StrMessage(action string) strMessage {
|
|||
return strMessage(action)
|
||||
}
|
||||
|
||||
var Quit = StrMessage("quit")
|
||||
|
||||
// Address implementation
|
||||
|
||||
type address struct {
|
||||
|
|
|
@ -50,7 +50,7 @@ func (t *T) TearDownApp() {
|
|||
// give actors time to recieve all messages:
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
//t.Check()
|
||||
t.Ctx.Services()["testing"].Mailbox() <- message.StrMessage("quit")
|
||||
t.Ctx.Services()["testing"].Mailbox() <- message.Quit
|
||||
fmt.Println("teardown ", t.Ctx.WaitGroup())
|
||||
t.Ctx.WaitGroup().Wait()
|
||||
//t.AssertNoUncheckedMessages()
|
||||
|
|
Loading…
Add table
Reference in a new issue