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():
|
case msg := <-ctx.Mailbox():
|
||||||
fmt.Println("message", msg)
|
fmt.Println("message", msg)
|
||||||
//ctx.LogDebug("dispatcherStep", m.Map{"msg": msg})
|
//ctx.LogDebug("dispatcherStep", m.Map{"msg": msg})
|
||||||
if msg == "quit" {
|
if msg.Action() == "quit" {
|
||||||
//ctx.LogInfo("Dispatcher stopped", m.Map{})
|
//ctx.LogInfo("Dispatcher stopped", m.Map{})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
//ctx.HandleMsg(msg)
|
return ctx.HandleMsg(msg)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdlib_context "context"
|
stdlib_context "context"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ func (ctx *context) Config() lib.Config {
|
||||||
return ctx.cfg
|
return ctx.cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *context) Parent() Context {
|
func (ctx *context) Parent() lib.Context {
|
||||||
return ctx.parent
|
return ctx.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +53,12 @@ func (ctx *context) Mailbox() chan lib.Message {
|
||||||
return ctx.mailbox
|
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 {
|
func (ctx *context) WaitGroup() *sync.WaitGroup {
|
||||||
return ctx.parent.WaitGroup()
|
return ctx.parent.WaitGroup()
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,14 @@ type Context interface {
|
||||||
State() ContextState
|
State() ContextState
|
||||||
WithState(ContextState) Context
|
WithState(ContextState) Context
|
||||||
Mailbox() chan Message
|
Mailbox() chan Message
|
||||||
|
HandleMsg(Message) bool
|
||||||
WaitGroup() *sync.WaitGroup
|
WaitGroup() *sync.WaitGroup
|
||||||
Stop()
|
Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message interface{}
|
type Message interface {
|
||||||
|
Action() string
|
||||||
|
}
|
||||||
|
|
||||||
type Action interface {
|
type Action interface {
|
||||||
Context() Context
|
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/app"
|
||||||
"git.sr.ht/~cco/go-scopes/lib"
|
"git.sr.ht/~cco/go-scopes/lib"
|
||||||
"git.sr.ht/~cco/go-scopes/lib/context"
|
"git.sr.ht/~cco/go-scopes/lib/context"
|
||||||
|
"git.sr.ht/~cco/go-scopes/lib/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Start(ctx lib.Context) {
|
func Start(ctx lib.Context) {
|
||||||
|
@ -49,7 +50,7 @@ func (t *T) TearDownApp() {
|
||||||
// give actors time to recieve all messages:
|
// give actors time to recieve all messages:
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
//t.Check()
|
//t.Check()
|
||||||
t.Ctx.Services()["testing"].Mailbox() <- "quit"
|
t.Ctx.Services()["testing"].Mailbox() <- message.StrMessage("quit")
|
||||||
fmt.Println("teardown ", t.Ctx.WaitGroup())
|
fmt.Println("teardown ", t.Ctx.WaitGroup())
|
||||||
t.Ctx.WaitGroup().Wait()
|
t.Ctx.WaitGroup().Wait()
|
||||||
//t.AssertNoUncheckedMessages()
|
//t.AssertNoUncheckedMessages()
|
||||||
|
|
|
@ -19,6 +19,7 @@ func TestConfig(tb *tbase.T) {
|
||||||
func TestingTest(t *testing.T) {
|
func TestingTest(t *testing.T) {
|
||||||
ctx := t.Ctx
|
ctx := t.Ctx
|
||||||
fmt.Println(ctx.Services())
|
fmt.Println(ctx.Services())
|
||||||
|
t.AssertEqual(len(ctx.Services()), 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigTest(t *testing.T) {
|
func ConfigTest(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue