promote inbox message to a shared type
This commit is contained in:
+4
-11
@@ -8,7 +8,6 @@ import (
|
||||
"log/slog"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Types
|
||||
@@ -42,15 +41,9 @@ type PeerStats struct {
|
||||
Worker WorkerStats
|
||||
}
|
||||
|
||||
type InboxMessage struct {
|
||||
ID string
|
||||
Data []byte
|
||||
ReceivedAt time.Time
|
||||
}
|
||||
|
||||
type PoolPlugin struct {
|
||||
ID string
|
||||
Inbox chan<- InboxMessage
|
||||
Inbox chan<- types.InboxMessage
|
||||
Events chan<- PoolEvent
|
||||
Errors chan<- error
|
||||
InboxCounter *atomic.Uint64
|
||||
@@ -73,7 +66,7 @@ type Pool struct {
|
||||
id string
|
||||
|
||||
peers map[string]*Peer
|
||||
inbox chan InboxMessage
|
||||
inbox chan types.InboxMessage
|
||||
events chan PoolEvent
|
||||
errors chan error
|
||||
|
||||
@@ -127,7 +120,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{},
|
||||
@@ -150,7 +143,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
@@ -407,7 +407,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,
|
||||
) {
|
||||
@@ -423,7 +423,7 @@ func RunForwarder(
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
case inbox <- InboxMessage{
|
||||
case inbox <- types.InboxMessage{
|
||||
ID: id,
|
||||
Data: msg.Data,
|
||||
ReceivedAt: msg.ReceivedAt,
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ import (
|
||||
)
|
||||
|
||||
func makeWorkerContext(t *testing.T) (
|
||||
inbox chan InboxMessage,
|
||||
inbox chan types.InboxMessage,
|
||||
events chan PoolEvent,
|
||||
errors chan error,
|
||||
pool PoolPlugin,
|
||||
) {
|
||||
t.Helper()
|
||||
inbox = make(chan InboxMessage, 256)
|
||||
inbox = make(chan types.InboxMessage, 256)
|
||||
events = make(chan PoolEvent, 10)
|
||||
errors = make(chan error, 10)
|
||||
pool = PoolPlugin{
|
||||
|
||||
Reference in New Issue
Block a user