Skip to content

Commit

Permalink
More robust error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 23, 2024
1 parent 762f07a commit 7fb10ee
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/live/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
require 'protocol/websocket'
require 'protocol/websocket/message'

require 'console/event/failure'

module Live
# Represents a connected client page with bound dynamic content areas.
class Page
Expand Down Expand Up @@ -74,7 +76,11 @@ def handle(id, event)

def close
@elements.each do |id, element|
element.close
begin
element.close
rescue => error
Console::Event::Failure.for(error).emit(self)
end
end
end

Expand Down Expand Up @@ -111,14 +117,14 @@ def run(connection)
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)

# Flush the output if there are no more updates:
connection.flush if @updates.empty?
end
end

while message = connection.read
Console.debug(self, "Reading message:", message)
process_message(message.parse)
end
ensure
Expand Down

0 comments on commit 7fb10ee

Please sign in to comment.