Skip to content

Commit 735d2d1

Browse files
ihabadhamclaude
andcommitted
Remove unused index variable from producer-consumer queue
The index was being created, enqueued, and then ignored in the writer. There's no ordering logic that uses it - the queue itself maintains FIFO order. Changes: - Remove `each_with_index` in build_producer_tasks (use `map`) - Enqueue chunks directly instead of `[idx, chunk]` pairs - Remove destructuring in build_writer_task - Simplify variable names (pair -> chunk, item -> chunk) Benefits: - Cleaner code - Slight performance improvement (no array allocation per chunk) - Removes misleading code (index suggested ordering logic that didn't exist) Verified: All 21 tests in stream_spec.rb still pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e039897 commit 735d2d1

File tree

1 file changed

+5
-6
lines changed
  • react_on_rails_pro/lib/react_on_rails_pro/concerns

1 file changed

+5
-6
lines changed

react_on_rails_pro/lib/react_on_rails_pro/concerns/stream.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def drain_streams_concurrently
9191
end
9292

9393
def build_producer_tasks(parent:, queue:)
94-
@rorp_rendering_fibers.each_with_index.map do |fiber, idx|
94+
@rorp_rendering_fibers.map do |fiber|
9595
parent.async do
9696
loop do
9797
# Check if client disconnected before expensive operations
@@ -101,7 +101,7 @@ def build_producer_tasks(parent:, queue:)
101101
break unless chunk
102102

103103
# Will be blocked if the queue is full until a chunk is dequeued
104-
queue.enqueue([idx, chunk])
104+
queue.enqueue(chunk)
105105
end
106106
rescue IOError, Errno::EPIPE
107107
# Client disconnected - stop producing
@@ -113,11 +113,10 @@ def build_producer_tasks(parent:, queue:)
113113
def build_writer_task(parent:, queue:)
114114
parent.async do
115115
loop do
116-
pair = queue.dequeue
117-
break if pair.nil?
116+
chunk = queue.dequeue
117+
break if chunk.nil?
118118

119-
_idx_from_queue, item = pair
120-
response.stream.write(item)
119+
response.stream.write(chunk)
121120
end
122121
rescue IOError, Errno::EPIPE
123122
# Client disconnected - stop writing

0 commit comments

Comments
 (0)