Compare commits
No commits in common. "250254d2df5af5b9e267e8e701ebe62a3dfb7e85" and "3f7bde8d302f351249fbad63d235a26df722d0d9" have entirely different histories.
250254d2df
...
3f7bde8d30
|
@ -13,7 +13,6 @@ class Test < Landline::App
|
||||||
puts "Client closed read connection"
|
puts "Client closed read connection"
|
||||||
end
|
end
|
||||||
socket.write("Hi!")
|
socket.write("Hi!")
|
||||||
puts IO.select([socket]).inspect
|
|
||||||
while (response = socket.read)
|
while (response = socket.read)
|
||||||
if response
|
if response
|
||||||
puts "Client wrote: #{response.inspect}"
|
puts "Client wrote: #{response.inspect}"
|
||||||
|
|
|
@ -24,6 +24,28 @@ module Landline
|
||||||
@__listeners[event]&.delete(listener)
|
@__listeners[event]&.delete(listener)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
# Trigger the queue clearing process
|
# Trigger the queue clearing process
|
||||||
|
@ -93,7 +115,6 @@ module Landline
|
||||||
rescue Errno::EPIPE => e
|
rescue Errno::EPIPE => e
|
||||||
_emit :error, e
|
_emit :error, e
|
||||||
close
|
close
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Read data from socket synchronously
|
# Read data from socket synchronously
|
||||||
|
@ -171,12 +192,6 @@ module Landline
|
||||||
close_write if @writable
|
close_write if @writable
|
||||||
end
|
end
|
||||||
|
|
||||||
# Obtain internal IO object
|
|
||||||
# @return [IO]
|
|
||||||
def to_io
|
|
||||||
io
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_reader :io, :readable, :writable
|
attr_reader :io, :readable, :writable
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -210,7 +225,6 @@ module Landline
|
||||||
rescue Errno::ECONNRESET => e
|
rescue Errno::ECONNRESET => e
|
||||||
_emit :error, e
|
_emit :error, e
|
||||||
close
|
close
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Receive data through websocket asynchronously
|
# Receive data through websocket asynchronously
|
||||||
|
@ -224,7 +238,6 @@ module Landline
|
||||||
rescue Errno::ECONNRESET => e
|
rescue Errno::ECONNRESET => e
|
||||||
_emit :error, e
|
_emit :error, e
|
||||||
close
|
close
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue