Compare commits
2 Commits
3f7bde8d30
...
250254d2df
Author | SHA1 | Date |
---|---|---|
Yessiest | 250254d2df | |
Yessiest | 582b0c1341 |
|
@ -13,6 +13,7 @@ class Test < Landline::App
|
|||
puts "Client closed read connection"
|
||||
end
|
||||
socket.write("Hi!")
|
||||
puts IO.select([socket]).inspect
|
||||
while (response = socket.read)
|
||||
if response
|
||||
puts "Client wrote: #{response.inspect}"
|
||||
|
|
|
@ -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
|
||||
|
@ -192,6 +171,12 @@ module Landline
|
|||
close_write if @writable
|
||||
end
|
||||
|
||||
# Obtain internal IO object
|
||||
# @return [IO]
|
||||
def to_io
|
||||
io
|
||||
end
|
||||
|
||||
attr_reader :io, :readable, :writable
|
||||
|
||||
private
|
||||
|
@ -225,6 +210,7 @@ module Landline
|
|||
rescue Errno::ECONNRESET => e
|
||||
_emit :error, e
|
||||
close
|
||||
nil
|
||||
end
|
||||
|
||||
# Receive data through websocket asynchronously
|
||||
|
@ -238,6 +224,7 @@ module Landline
|
|||
rescue Errno::ECONNRESET => e
|
||||
_emit :error, e
|
||||
close
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue