DEV Community

Discussion on: HELP NEEDED: Understanding Rails ActionController::Live Module (and Async Limitations)

Collapse
 
isalevine profile image
Isa Levine

That's what I thought too! One of the things I tried was moving the 5.times do loop outside of the begin statement, so that a new SSE is opened and closed once per loop:

        5.times do  
            sse = SSE.new(response.stream)
            begin
                # 5.times do      
                    character_hash = {
                        "uuid": SecureRandom.uuid,
                        "name": name_array.sample,
                        "hp": hp_array.sample,
                        "magic": magic_array.sample
                    }
                    sse.write({ character: character_hash })
                    sleep 1
                # end
            rescue IOError
                # client disconnected
            ensure
                sse.close
            end
        end

And fascinatingly, only ONE character is generated and sent now! Whyyyyy Rails, why won't you let me send multiple SSEs?!

Collapse
 
256hz profile image
Abe Dolinger • Edited

That's interesting. Well, at least it confirms it's waiting for the end of the stream to finish receiving. I wonder if the receiver can be somehow switched back into a state of listening for a new connection at that point?