starting with the simplest message implementation: just string
This commit is contained in:
parent
1cd31ffb48
commit
c182385353
6 changed files with 28 additions and 5 deletions
|
@ -43,11 +43,11 @@ func step(ctx lib.Context, sig <-chan os.Signal) bool {
|
|||
case msg := <-ctx.Mailbox():
|
||||
fmt.Println("message", msg)
|
||||
//ctx.LogDebug("dispatcherStep", m.Map{"msg": msg})
|
||||
if msg == "quit" {
|
||||
if msg.Action() == "quit" {
|
||||
//ctx.LogInfo("Dispatcher stopped", m.Map{})
|
||||
return false
|
||||
}
|
||||
//ctx.HandleMsg(msg)
|
||||
return ctx.HandleMsg(msg)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package context
|
|||
|
||||
import (
|
||||
stdlib_context "context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -24,7 +25,7 @@ func (ctx *context) Config() lib.Config {
|
|||
return ctx.cfg
|
||||
}
|
||||
|
||||
func (ctx *context) Parent() Context {
|
||||
func (ctx *context) Parent() lib.Context {
|
||||
return ctx.parent
|
||||
}
|
||||
|
||||
|
@ -52,6 +53,12 @@ func (ctx *context) Mailbox() chan lib.Message {
|
|||
return ctx.mailbox
|
||||
}
|
||||
|
||||
func (ctx *context) HandleMsg(msg lib.Message) bool {
|
||||
fmt.Println("HandleMsg ", msg)
|
||||
// return ctx.Config().MessageHandler()(ctx, msg)
|
||||
return true
|
||||
}
|
||||
|
||||
func (ctx *context) WaitGroup() *sync.WaitGroup {
|
||||
return ctx.parent.WaitGroup()
|
||||
}
|
||||
|
|
|
@ -38,11 +38,14 @@ type Context interface {
|
|||
State() ContextState
|
||||
WithState(ContextState) Context
|
||||
Mailbox() chan Message
|
||||
HandleMsg(Message) bool
|
||||
WaitGroup() *sync.WaitGroup
|
||||
Stop()
|
||||
}
|
||||
|
||||
type Message interface{}
|
||||
type Message interface {
|
||||
Action() string
|
||||
}
|
||||
|
||||
type Action interface {
|
||||
Context() Context
|
||||
|
|
11
lib/message/message.go
Normal file
11
lib/message/message.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package message
|
||||
|
||||
type strMessage string
|
||||
|
||||
func (msg strMessage) Action() string {
|
||||
return string(msg)
|
||||
}
|
||||
|
||||
func StrMessage(action string) strMessage {
|
||||
return strMessage(action)
|
||||
}
|
|
@ -11,6 +11,7 @@ import (
|
|||
"git.sr.ht/~cco/go-scopes/app"
|
||||
"git.sr.ht/~cco/go-scopes/lib"
|
||||
"git.sr.ht/~cco/go-scopes/lib/context"
|
||||
"git.sr.ht/~cco/go-scopes/lib/message"
|
||||
)
|
||||
|
||||
func Start(ctx lib.Context) {
|
||||
|
@ -49,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() <- "quit"
|
||||
t.Ctx.Services()["testing"].Mailbox() <- message.StrMessage("quit")
|
||||
fmt.Println("teardown ", t.Ctx.WaitGroup())
|
||||
t.Ctx.WaitGroup().Wait()
|
||||
//t.AssertNoUncheckedMessages()
|
||||
|
|
|
@ -19,6 +19,7 @@ func TestConfig(tb *tbase.T) {
|
|||
func TestingTest(t *testing.T) {
|
||||
ctx := t.Ctx
|
||||
fmt.Println(ctx.Services())
|
||||
t.AssertEqual(len(ctx.Services()), 2)
|
||||
}
|
||||
|
||||
func ConfigTest(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue