Rails app hangs when there's a server sent event (SSE) that requires database actions
问题 I'm learning & doing SSE for the first time in rails! My controller code: def update response.headers['Content-Type'] = 'text/event-stream' sse = SSE.new(response.stream, event: 'notice') begin User.listen_to_creation do |user_id| sse.write({id: user_id}) end rescue ClientDisconnected ensure sse.close end end Front end: var source = new EventSource('/site_update'); source.addEventListener('notice', function(event) { var data = JSON.parse(event.data) console.log(data) }); Model pub/sub class