From b0648496251ad7aeb7577b7e62223a0f055daf2a Mon Sep 17 00:00:00 2001 From: Ara Park Date: Fri, 8 Dec 2023 17:33:43 +0900 Subject: [PATCH] fix: only link init hook when action is not nil (#43) --- pkg/node/onetomany.go | 16 +++++++++------- pkg/node/onetoone.go | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/node/onetomany.go b/pkg/node/onetomany.go index 464aaa87..f1b7d268 100644 --- a/pkg/node/onetomany.go +++ b/pkg/node/onetomany.go @@ -28,7 +28,7 @@ func NewOneToManyNode(action func(*process.Process, *packet.Packet) ([]*packet.P errPort: port.New(), } - if action != nil { + if n.action != nil { n.inPort.AddInitHook(port.InitHookFunc(n.forward)) n.errPort.AddInitHook(port.InitHookFunc(func(proc *process.Process) { n.mu.RLock() @@ -58,14 +58,16 @@ func (n *OneToManyNode) Port(name string) (*port.Port, bool) { for j := 0; j <= i; j++ { if len(n.outPorts) <= j { outPort := port.New() - outPort.AddInitHook(port.InitHookFunc(func(proc *process.Process) { - n.mu.RLock() - defer n.mu.RUnlock() + if n.action != nil { + outPort.AddInitHook(port.InitHookFunc(func(proc *process.Process) { + n.mu.RLock() + defer n.mu.RUnlock() - outStream := outPort.Open(proc) + outStream := outPort.Open(proc) - n.backward(proc, outStream) - })) + n.backward(proc, outStream) + })) + } n.outPorts = append(n.outPorts, outPort) } } diff --git a/pkg/node/onetoone.go b/pkg/node/onetoone.go index 228e653a..c2a390b2 100644 --- a/pkg/node/onetoone.go +++ b/pkg/node/onetoone.go @@ -30,7 +30,7 @@ func NewOneToOneNode(action func(*process.Process, *packet.Packet) (*packet.Pack errPort: port.New(), } - if action != nil { + if n.action != nil { n.ioPort.AddInitHook(port.InitHookFunc(func(proc *process.Process) { n.mu.RLock() defer n.mu.RUnlock()