From 660061d775f2c86fa5799ce405614b3010b96fcc Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 24 Apr 2024 14:40:39 +1200 Subject: [PATCH] Remove dependency on `async-io`. --- async-websocket.gemspec | 3 +-- examples/chat/client.rb | 7 +------ examples/chat/multi-client.rb | 3 +-- examples/mud/client.rb | 7 +------ examples/polygon.io/client.rb | 1 - fixtures/rack_application/client.rb | 7 +------ guides/getting-started/readme.md | 7 +------ 7 files changed, 6 insertions(+), 29 deletions(-) diff --git a/async-websocket.gemspec b/async-websocket.gemspec index 523f6e1..0d18b2c 100644 --- a/async-websocket.gemspec +++ b/async-websocket.gemspec @@ -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 diff --git a/examples/chat/client.rb b/examples/chat/client.rb index 771b935..ca0c19d 100755 --- a/examples/chat/client.rb +++ b/examples/chat/client.rb @@ -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' @@ -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 diff --git a/examples/chat/multi-client.rb b/examples/chat/multi-client.rb index 45f21c4..c88d8b9 100755 --- a/examples/chat/multi-client.rb +++ b/examples/chat/multi-client.rb @@ -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' @@ -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 diff --git a/examples/mud/client.rb b/examples/mud/client.rb index 67e7991..1409552 100755 --- a/examples/mud/client.rb +++ b/examples/mud/client.rb @@ -6,7 +6,6 @@ # Copyright, 2020, by Juan Antonio Martín Lucas. require 'async' -require 'async/io/stream' require 'async/http/endpoint' require 'async/websocket/client' @@ -14,17 +13,13 @@ 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 diff --git a/examples/polygon.io/client.rb b/examples/polygon.io/client.rb index 3cdeeb0..d183baf 100644 --- a/examples/polygon.io/client.rb +++ b/examples/polygon.io/client.rb @@ -5,7 +5,6 @@ # Copyright, 2020-2022, by Samuel Williams. require 'async' -require 'async/io/stream' require 'async/http/endpoint' require 'hexdump' diff --git a/fixtures/rack_application/client.rb b/fixtures/rack_application/client.rb index 98eca72..f9977d2 100644 --- a/fixtures/rack_application/client.rb +++ b/fixtures/rack_application/client.rb @@ -5,7 +5,6 @@ # Copyright, 2018-2023, by Samuel Williams. require 'async' -require 'async/io/stream' require 'async/http/endpoint' require 'async/websocket/client' @@ -13,16 +12,12 @@ 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 diff --git a/guides/getting-started/readme.md b/guides/getting-started/readme.md index ccd20ae..50f64a6 100644 --- a/guides/getting-started/readme.md +++ b/guides/getting-started/readme.md @@ -20,7 +20,6 @@ $ bundle add async-websocket #!/usr/bin/env ruby require 'async' -require 'async/io/stream' require 'async/http/endpoint' require 'async/websocket/client' @@ -28,15 +27,11 @@ 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