Skip to content

Commit

Permalink
Merge 9ab70f7 into 98d915e
Browse files Browse the repository at this point in the history
  • Loading branch information
baxter2 committed May 13, 2019
2 parents 98d915e + 9ab70f7 commit 8f35998
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@ USER = ARGV.pop || "anonymous"
URL = ARGV.pop || "http://localhost:7070"

Async do |task|
stdin = Async::IO::Stream.new(
Async::IO::Generic.new($stdin)
)
stdin = Async::IO::Stream.new(
Async::IO::Generic.new($stdin)
)

endpoint = Async::HTTP::URLEndpoint.parse(URL)
endpoint = Async::HTTP::URLEndpoint.parse(URL)

Async::WebSocket::Client.open(endpoint) do |connection|
input_task = task.async do
while line = stdin.read_until("\n")
connection.write({user: USER, text: line})
connection.flush
end
end
Async::WebSocket::Client.open(endpoint) do |connection|
input_task = task.async do
while line = stdin.read_until("\n")
connection.write({user: USER, text: line})
connection.flush
end
end

connection.write({
user: USER,
status: "connected",
})
connection.write({
user: USER,
status: "connected",
})

while message = connection.read
puts message.inspect
end
ensure
input_task&.stop
end
while message = connection.read
puts message.inspect
end
ensure
input_task&.stop
end
end
```

Expand All @@ -81,18 +81,18 @@ require 'set'
$connections = Set.new

run lambda {|env|
Async::WebSocket::Server::Rack.open(env, protocols: ['ws']) do |connection|
$connections << connection
Async::WebSocket::Server::Rack.open(env, protocols: ['ws']) do |connection|
$connections << connection

while message = connection.read
$connections.each do |connection|
connection.write(message)
connection.flush
end
end
ensure
$connections.delete(connection)
end or [200, {}, ["Hello World"]]
while message = connection.read
$connections.each do |connection|
connection.write(message)
connection.flush
end
end
ensure
$connections.delete(connection)
end or [200, {}, ["Hello World"]]
}
```

Expand Down

0 comments on commit 8f35998

Please sign in to comment.