promote inbox message to a shared type

This commit is contained in:
Jay
2026-05-03 10:41:11 -04:00
parent ab641e8313
commit efdbf7b37f
10 changed files with 30 additions and 35 deletions
+4 -11
View File
@@ -9,7 +9,6 @@ import (
"log/slog"
"sync"
"sync/atomic"
"time"
)
// Types
@@ -55,14 +54,8 @@ type PeerStats struct {
Connection transport.ConnectionStats
}
type InboxMessage struct {
ID string
Data []byte
ReceivedAt time.Time
}
type PoolPlugin struct {
Inbox chan<- InboxMessage
Inbox chan<- types.InboxMessage
Events chan<- PoolEvent
Errors chan<- error
InboxCounter *atomic.Uint64
@@ -86,7 +79,7 @@ type Pool struct {
id string
peers map[string]*Peer
inbox chan InboxMessage
inbox chan types.InboxMessage
events chan PoolEvent
errors chan error
@@ -143,7 +136,7 @@ func NewPool(ctx context.Context, id string, config *PoolConfig, handler slog.Ha
cancel: cancel,
id: id,
peers: make(map[string]*Peer),
inbox: make(chan InboxMessage, config.InboxBufferSize),
inbox: make(chan types.InboxMessage, config.InboxBufferSize),
events: make(chan PoolEvent, config.EventsBufferSize),
errors: make(chan error, config.ErrorsBufferSize),
inboxCounter: &atomic.Uint64{},
@@ -166,7 +159,7 @@ func (p *Pool) Peers() []string {
return ids
}
func (p *Pool) Inbox() <-chan InboxMessage {
func (p *Pool) Inbox() <-chan types.InboxMessage {
return p.inbox
}
+2 -2
View File
@@ -252,7 +252,7 @@ func RunForwarder(
id string,
ctx context.Context,
messages <-chan types.ReceivedMessage,
inbox chan<- InboxMessage,
inbox chan<- types.InboxMessage,
workerProcessedCount *atomic.Uint64,
poolInboxCount *atomic.Uint64,
) {
@@ -268,7 +268,7 @@ func RunForwarder(
case <-ctx.Done():
return
case inbox <- InboxMessage{
case inbox <- types.InboxMessage{
ID: id,
Data: msg.Data,
ReceivedAt: msg.ReceivedAt,
+1 -1
View File
@@ -13,7 +13,7 @@ func TestRunForwarder(t *testing.T) {
t.Run("message passes through to inbox", func(t *testing.T) {
id := "wss://test"
messages := make(chan types.ReceivedMessage, 1)
inbox := make(chan InboxMessage, 1)
inbox := make(chan types.InboxMessage, 1)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
+4 -3
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"git.wisehodl.dev/jay/go-honeybee/honeybeetest"
"git.wisehodl.dev/jay/go-honeybee/transport"
"git.wisehodl.dev/jay/go-honeybee/types"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"sync"
@@ -19,7 +20,7 @@ type workerTestVars struct {
incoming chan honeybeetest.MockIncomingData
outgoing chan honeybeetest.MockOutgoingData
pool PoolPlugin
inbox chan InboxMessage
inbox chan types.InboxMessage
events chan PoolEvent
exitKind *atomic.Value
wg *sync.WaitGroup
@@ -36,7 +37,7 @@ func setupWorkerTest(t *testing.T) workerTestVars {
assert.NoError(t, err)
worker.cancel = cancel
inbox := make(chan InboxMessage, 256)
inbox := make(chan types.InboxMessage, 256)
events := make(chan PoolEvent, 10)
exitKind := &atomic.Value{}
@@ -134,7 +135,7 @@ func TestWorkerStart(t *testing.T) {
exitKind := &atomic.Value{}
var once sync.Once
pool := PoolPlugin{
Inbox: make(chan InboxMessage, 256),
Inbox: make(chan types.InboxMessage, 256),
Events: make(chan PoolEvent, 10),
OnExit: func(kind WorkerExitKind) {
once.Do(func() { exitKind.Store(kind) })