From 10386651a4ca7cb7b511430ca37c6823bc39c6f1 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Wed, 26 Jul 2023 14:56:54 +0200 Subject: [PATCH] minor re-arrangement; prepare disconnect() function --- matrix/matrix.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/matrix/matrix.go b/matrix/matrix.go index 335953d..817f666 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -17,21 +17,21 @@ func create(act lib.Action) bool { //spec := act.Spec() msg := act.Message() cctx := createCell(ctx) - connect(ctx, cctx, msg) - connect(cctx, msg.Sender().Cell(), msg) + pattern := config.Pattern(msg.Domain(), "data", msg.Class(), msg.Item()).String() + connect(ctx, cctx, pattern) + connect(cctx, msg.Sender().Cell(), pattern) return true } func createCell(ctx lib.Context) lib.Context { cfg := DefaultConfig("") - cctx := ctx.ChildContext(cfg) + cctx := ctx.ChildContext(cfg) // .WithState(...) cfg.Starter()(cctx) return cctx } -func connect(src, tgt lib.Context, msg lib.Message) { +func connect(src, tgt lib.Context, pattern string) { cfg := src.Config() - pattern := config.Pattern(msg.Domain(), "data", msg.Class(), msg.Item()).String() for _, act := range cfg.Actions() { if act.Pattern().String() == pattern { for _, spec := range act.Specs() { @@ -43,6 +43,17 @@ func connect(src, tgt lib.Context, msg lib.Message) { cfg.AddAction(pattern, action.Base(handle).AddReceiver(tgt)) } +func disconnect(src, tgt lib.Context) { //, pattern string) { + cfg := src.Config() + for _, act := range cfg.Actions() { + //if act.Pattern().String() == pattern { + for _, spec := range act.Specs() { + //spec.RemoveReceiver(tgt) + } + //} + } +} + func handle(act lib.Action) bool { // here comes the real stuff return action.Forward(act)