Skip to content

Commit

Permalink
Add Sync{} around Live::Page#run.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jul 3, 2024
1 parent 1012919 commit 05b5235
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/live/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,23 @@ def process_message(message)
# Run the event handling loop with the given websocket connection.
# @parameter connection [Async::WebSocket::Connection]
def run(connection)
queue_task = Async do
while update = @updates.dequeue
Console.debug(self, "Sending update:", update)
::Protocol::WebSocket::TextMessage.generate(update).send(connection)
connection.flush if @updates.empty?
Sync do |task|
queue_task = task.async do
while update = @updates.dequeue
Console.debug(self, "Sending update:", update)
::Protocol::WebSocket::TextMessage.generate(update).send(connection)
connection.flush if @updates.empty?
end
end

while message = connection.read
Console.debug(self, "Reading message:", message)
process_message(message.parse)
end
ensure
self.close
queue_task&.stop
end

while message = connection.read
Console.debug(self, "Reading message:", message)
process_message(message.parse)
end
ensure
self.close
queue_task&.stop
end
end
end
end

0 comments on commit 05b5235

Please sign in to comment.