Class: Sidekiq::Mcp::SseMiddleware::SseStreamer

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/mcp/sse_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id, middleware) ⇒ SseStreamer

Returns a new instance of SseStreamer.



129
130
131
132
# File 'lib/sidekiq/mcp/sse_middleware.rb', line 129

def initialize(client_id, middleware)
  @client_id = client_id
  @middleware = middleware
end

Instance Method Details

#each {|"data: #{initial_message.to_json}\n\n"| ... } ⇒ Object

Yields:

  • ("data: #{initial_message.to_json}\n\n")


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/sidekiq/mcp/sse_middleware.rb', line 134

def each
  @middleware.add_client(@client_id, self)
  
  # Send initial connection message
  yield "data: #{initial_message.to_json}\n\n"
  
  # Keep connection alive with heartbeats
  begin
    loop do
      sleep 30
      yield ": heartbeat\n\n"
    end
  rescue
    # Connection closed
  ensure
    @middleware.remove_client(@client_id)
  end
end

#flushObject



157
158
159
160
161
# File 'lib/sidekiq/mcp/sse_middleware.rb', line 157

def flush
  # This method is called by broadcast_to_clients
  # In a real streaming setup, we'd need to queue messages
  # For now, this is a simplified implementation
end

#write(data) ⇒ Object



153
154
155
# File 'lib/sidekiq/mcp/sse_middleware.rb', line 153

def write(data)
  @data = data
end