Skip to content

Commit

Permalink
Remove dependency on async-io.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 24, 2024
1 parent bbd45e3 commit 660061d
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 29 deletions.
3 changes: 1 addition & 2 deletions async-websocket.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 3.0"

spec.add_dependency "async-http", "~> 0.54"
spec.add_dependency "async-io", "~> 1.23"
spec.add_dependency "protocol-rack", "~> 0.1"
spec.add_dependency "protocol-rack", "~> 0.5"
spec.add_dependency "protocol-websocket", "~> 0.11"
end
7 changes: 1 addition & 6 deletions examples/chat/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Copyright, 2018-2022, by Samuel Williams.

require 'async'
require 'async/io/stream'
require 'async/http/endpoint'
require_relative '../../lib/async/websocket/client'
require 'protocol/websocket/json_message'
Expand All @@ -15,13 +14,9 @@
ENDPOINT = Async::HTTP::Endpoint.parse(URL)

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

Async::WebSocket::Client.connect(ENDPOINT) do |connection|
input_task = task.async do
while line = stdin.read_until("\n")
while line = $stdin.gets
message = Protocol::WebSocket::JSONMessage.generate({text: line})
message.send(connection)
connection.flush
Expand Down
3 changes: 1 addition & 2 deletions examples/chat/multi-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
require 'async'
require 'async/semaphore'
require 'async/clock'
require 'async/io/stream'
require 'async/http/endpoint'
require 'protocol/websocket/json_message'
require_relative '../../lib/async/websocket/client'
Expand All @@ -28,7 +27,7 @@ class Command < Samovar::Command

def local_address
if bind = @options[:bind]
Async::IO::Address.tcp(bind, 0)
Addrinfo.tcp(bind, 0)
end
end

Expand Down
7 changes: 1 addition & 6 deletions examples/mud/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@
# Copyright, 2020, by Juan Antonio Martín Lucas.

require 'async'
require 'async/io/stream'
require 'async/http/endpoint'
require 'async/websocket/client'

USER = ARGV.pop || "anonymous"
URL = ARGV.pop || "http://127.0.0.1:7070"

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

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

Async::WebSocket::Client.connect(endpoint) do |connection|
task.async do
$stdout.write "> "

while line = stdin.read_until("\n")
while line = $stdin.gets
connection.write({input: line})
connection.flush

Expand Down
1 change: 0 additions & 1 deletion examples/polygon.io/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Copyright, 2020-2022, by Samuel Williams.

require 'async'
require 'async/io/stream'
require 'async/http/endpoint'

require 'hexdump'
Expand Down
7 changes: 1 addition & 6 deletions fixtures/rack_application/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@
# Copyright, 2018-2023, by Samuel Williams.

require 'async'
require 'async/io/stream'
require 'async/http/endpoint'
require 'async/websocket/client'

USER = ARGV.pop || "anonymous"
URL = ARGV.pop || "http://localhost:7070"

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

endpoint = Async::HTTP::Endpoint.parse(URL)
headers = {'token' => 'wubalubadubdub'}

Async::WebSocket::Client.open(endpoint, headers: headers) do |connection|
input_task = task.async do
while line = stdin.read_until("\n")
while line = $stdin.gets
connection.write({user: USER, text: line})
connection.flush
end
Expand Down
7 changes: 1 addition & 6 deletions guides/getting-started/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@ $ bundle add async-websocket
#!/usr/bin/env ruby

require 'async'
require 'async/io/stream'
require 'async/http/endpoint'
require 'async/websocket/client'

USER = ARGV.pop || "anonymous"
URL = ARGV.pop || "http://localhost:7070"

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

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

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

0 comments on commit 660061d

Please sign in to comment.