further fixes for websockets

This commit is contained in:
Yessiest 2024-07-08 17:07:50 +04:00
parent 3f7bde8d30
commit 582b0c1341
1 changed files with 3 additions and 22 deletions

View File

@ -24,28 +24,6 @@ module Landline
@__listeners[event]&.delete(listener)
end
# Await for an event
# @param event [Symbol, Array<Symbol>] event or array of events to wait for
# @return [Array]
# @sg-ignore
def await(event)
blocking = true
output = nil
listener = proc do |*data|
output = data
blocking = false
end
if event.is_a? Array
event.each { |x| on(x, &listener) }
else
on(event, &listener)
end
while blocking; end
return output[0] if output.is_a? Array and output.length == 1
output
end
private
# Trigger the queue clearing process
@ -115,6 +93,7 @@ module Landline
rescue Errno::EPIPE => e
_emit :error, e
close
nil
end
# Read data from socket synchronously
@ -225,6 +204,7 @@ module Landline
rescue Errno::ECONNRESET => e
_emit :error, e
close
nil
end
# Receive data through websocket asynchronously
@ -238,6 +218,7 @@ module Landline
rescue Errno::ECONNRESET => e
_emit :error, e
close
nil
end
end
end