work in progress: set up types for message processing

This commit is contained in:
Helmut Merz 2023-06-04 15:34:25 +02:00
parent 2a188cfa1a
commit 1cd31ffb48
3 changed files with 30 additions and 3 deletions

View file

@ -47,7 +47,7 @@ func step(ctx lib.Context, sig <-chan os.Signal) bool {
//ctx.LogInfo("Dispatcher stopped", m.Map{}) //ctx.LogInfo("Dispatcher stopped", m.Map{})
return false return false
} }
//ctx.HandleMsg(&msg) //ctx.HandleMsg(msg)
} }
return true return true
} }

View file

@ -20,6 +20,7 @@ func Start(ctx lib.Context) {
type Base struct { type Base struct {
name string name string
starter lib.StartProc starter lib.StartProc
actions []lib.ActionConfig
children []lib.Config children []lib.Config
} }
@ -31,6 +32,10 @@ func (cfg *Base) Starter() lib.StartProc {
return cfg.starter return cfg.starter
} }
func (cfg *Base) Actions() []lib.ActionConfig {
return cfg.actions
}
func (cfg *Base) Children() []lib.Config { func (cfg *Base) Children() []lib.Config {
return cfg.children return cfg.children
} }
@ -43,6 +48,7 @@ func MakeBase(name string, starter lib.StartProc) *Base {
return &Base{ return &Base{
name: name, name: name,
starter: starter, starter: starter,
actions: nil,
} }
} }

View file

@ -1,3 +1,5 @@
// Package `lib` provides a set of common types (mostly interfaces
// and function declarations) and some basic functions.
package lib package lib
import ( import (
@ -5,15 +7,24 @@ import (
"sync" "sync"
) )
type ActionSpec interface {
Handler() ActionHandler
Receivers() []string
}
type ActionConfig interface {
Pattern() string
Specs() []ActionSpec
}
type Config interface { type Config interface {
Name() string Name() string
Starter() StartProc Starter() StartProc
Actions() []ActionConfig
Children() []Config Children() []Config
Add(Config) Add(Config)
} }
type Message interface{}
type Services map[string]Context type Services map[string]Context
type ContextState interface{} type ContextState interface{}
@ -31,8 +42,18 @@ type Context interface {
Stop() Stop()
} }
type Message interface{}
type Action interface {
Context() Context
Spec() ActionSpec
Message() Message
}
type Proc = func(Context) type Proc = func(Context)
type StartProc = Proc type StartProc = Proc
type MessageHandler = func(Context, Message)
type ActionHandler = func(Action)
// async Runners // async Runners