MCPcopy Create free account
hub / github.com/coder/aibridge / NewEventStream

Function NewEventStream

intercept/eventstream/eventstream.go:46–62  ·  view source on GitHub ↗

NewEventStream creates a new SSE stream, with an optional payload which is used to send pings every [pingInterval].

(ctx context.Context, logger slog.Logger, pingPayload []byte)

Source from the content-addressed store, hash-verified

44
45// NewEventStream creates a new SSE stream, with an optional payload which is used to send pings every [pingInterval].
46func NewEventStream(ctx context.Context, logger slog.Logger, pingPayload []byte) *EventStream {
47 // Send periodic pings to keep connections alive.
48 // The upstream provider may also send their own pings, but we can't rely on this.
49 tick := time.NewTicker(time.Nanosecond)
50 tick.Stop() // Ticker will start after stream initiation.
51
52 return &EventStream{
53 ctx: ctx,
54 logger: logger,
55
56 pingPayload: pingPayload,
57
58 eventsCh: make(chan event, 128), // Small buffer to unblock senders; once full, senders will block.
59 doneCh: make(chan struct{}),
60 tick: tick,
61 }
62}
63
64// InitiateStream initiates the SSE stream by sending headers and starting the
65// ping ticker. This is safe to call multiple times as only the first call has

Callers 3

ProcessRequestMethod · 0.92
ProcessRequestMethod · 0.92
ProcessRequestMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected