MCPcopy Index your code
hub / github.com/coder/coder / NewEventStream

Function NewEventStream

aibridge/intercept/eventstream/eventstream.go:53–70  ·  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, clk quartz.Clock)

Source from the content-addressed store, hash-verified

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

Calls 1

StopMethod · 0.65