Skip to content

Commit

Permalink
Add echo block - used for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
g41797 committed Aug 8, 2023
1 parent 8a36689 commit 991d14c
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions echo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package sputnik

import (
"github.com/g41797/kissngoqueue"
)

const EchoBlockName = "echo"

// Echo block is used for debugging
// It replaces not implemented block
// Just assign required responsibility.
// During creation it also get Queue[Msg]
// - created by test
// - stored in factory
// Every retrieved message will be put in this queue.
// for further getting by test
type echo struct {
q *kissngoqueue.Queue[Msg]
done chan struct{}
}

func (bl *echo) init(_ ConfFactory) error {
bl.done = make(chan struct{})
return nil
}

func (bl *echo) finish(init bool) {
close(bl.done)
return
}

func (bl *echo) run(_ BlockCommunicator) {
defer bl.q.CancelMT()
<-bl.done
return
}

func (bl *echo) onMsg(msg Msg) {
if bl.q != nil {
bl.q.PutMT(msg)
}
return
}

type echoFactory struct {
q *kissngoqueue.Queue[Msg]
}

func (ef *echoFactory) createEchoBlock() *Block {
echo := new(echo)
echo.q = ef.q
block := NewBlock(
WithInit(echo.init),
WithRun(echo.run),
WithFinish(echo.finish),
WithOnMsg(echo.onMsg))
return block

}

func EchoBlockFactory(q *kissngoqueue.Queue[Msg]) BlockFactory {
ef := new(echoFactory)
ef.q = q
return ef.createEchoBlock
}

0 comments on commit 991d14c

Please sign in to comment.