Context.Send() for basic send functionality
This commit is contained in:
parent
9a609ce880
commit
c2eab31527
3 changed files with 17 additions and 2 deletions
|
@ -60,6 +60,10 @@ func (ctx *context) Done() <-chan struct{} {
|
|||
return ctx.parent.Done()
|
||||
}
|
||||
|
||||
func (ctx *context) Send(msg lib.Message) {
|
||||
ctx.Mailbox() <- msg
|
||||
}
|
||||
|
||||
func (ctx *context) Stop() {
|
||||
// ctx.Warn("Only application-level service can be stopped
|
||||
}
|
||||
|
|
|
@ -61,3 +61,13 @@ func ParseAddress(s string) lib.Address {
|
|||
}
|
||||
return &addr
|
||||
}
|
||||
|
||||
// Addressable interface
|
||||
|
||||
func (addr *address) Address() lib.Address {
|
||||
return addr
|
||||
}
|
||||
|
||||
func (_ *address) Cell() lib.Context {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ type Context interface {
|
|||
Mailbox() chan Message
|
||||
WaitGroup() *sync.WaitGroup
|
||||
Stop()
|
||||
Send(Message)
|
||||
}
|
||||
|
||||
// message, address
|
||||
|
@ -128,8 +129,8 @@ func HandleMsg(ctx Context, msg Message) bool {
|
|||
}
|
||||
|
||||
func Send(ctx Context, addr Address, msg Message) {
|
||||
if srv, ok := ctx.Services()[addr.Service()]; ok {
|
||||
srv.Mailbox() <- msg
|
||||
if svc, ok := ctx.Services()[addr.Service()]; ok {
|
||||
svc.Send(msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue