incorporate observer interface into components

This commit is contained in:
Jay
2026-05-19 21:20:00 -04:00
parent ce0b13e914
commit 30e9881dae
7 changed files with 118 additions and 78 deletions
+27 -24
View File
@@ -6,6 +6,7 @@ import (
"encoding/base32"
"fmt"
"git.wisehodl.dev/jay/go-mana-component"
"git.wisehodl.dev/jay/go-mana-prism/observer"
"git.wisehodl.dev/jay/go-roots-ws"
"log/slog"
"sync"
@@ -28,21 +29,6 @@ type ReqClosed struct {
Data string
}
type RequestManager struct {
reqs map[string]*request
envoy *Envoy
events <-chan OutboundPoolEvent
inbox <-chan InboxMessage
ctx context.Context
cancel context.CancelFunc
mu sync.RWMutex
wg sync.WaitGroup
handler slog.Handler
logger *slog.Logger
}
// ----------------------------------------------------------------------------
// ID Generation
// ----------------------------------------------------------------------------
@@ -80,6 +66,26 @@ func WithLabel(label string) RequestOption {
return func(o *requestOptions) { o.label = label }
}
// ----------------------------------------------------------------------------
// Request Manager
// ----------------------------------------------------------------------------
type RequestManager struct {
reqs map[string]*request
envoy *Envoy
events <-chan OutboundPoolEvent
inbox <-chan InboxMessage
ctx context.Context
cancel context.CancelFunc
mu sync.RWMutex
wg sync.WaitGroup
observer observer.Observer
handler slog.Handler
logger *slog.Logger
}
type request struct {
id string
filters [][]byte
@@ -95,10 +101,6 @@ type request struct {
closedOnce sync.Once
}
// ----------------------------------------------------------------------------
// Request Manager
// ----------------------------------------------------------------------------
func NewRequestManager(e *Envoy) *RequestManager {
ctx, cancel := context.WithCancel(
component.MustExtend(e.Context(), "request_manager"))
@@ -110,14 +112,15 @@ func NewRequestManager(e *Envoy) *RequestManager {
events: e.SubscribeEvents(),
inbox: e.SubscribeInbox([]string{"EVENT", "EOSE", "CLOSED"}),
ctx: ctx,
cancel: cancel,
ctx: ctx,
cancel: cancel,
observer: e.Observer(),
handler: e.Handler(),
}
if h := e.Handler(); h != nil {
if m.handler != nil {
comp := component.FromContext(ctx)
m.handler = h
m.logger = slog.New(h).With(slog.Any("component", comp))
m.logger = slog.New(m.handler).With(slog.Any("component", comp))
}
m.wg.Add(2)