Skip to content

Commit 3742d2a

Browse files
committed
WIP: upgrade async-websocket.
1 parent c4a1fe9 commit 3742d2a

File tree

2 files changed

+10
-7
lines changed
  • examples/hi_real_time_async_async
  • lib/slack/real_time/concurrency

2 files changed

+10
-7
lines changed

examples/hi_real_time_async_async/Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ source 'http://rubygems.org'
33

44
gem 'slack-ruby-client', path: '../..'
55

6-
gem 'async-websocket'
6+
gem 'async-websocket', '> 0.9'
7+
gem 'io-endpoint'
78
gem 'foreman'

lib/slack/real_time/concurrency/async.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
require 'async/websocket'
33
require 'async/notification'
44
require 'async/clock'
5+
require 'io/endpoint/host_endpoint'
6+
require 'io/endpoint/ssl_endpoint'
57

68
module Slack
79
module RealTime
@@ -47,10 +49,10 @@ def start_reactor(client)
4749
@client_task = task.async do |subtask|
4850
subtask.annotate "#{client} run-loop"
4951
client.run_loop
50-
rescue ::Async::Wrapper::Cancelled => e
52+
rescue ::Async::Timeout::CancelledError => e
5153
# Will get restarted by ping worker.
5254
rescue StandardError => e
53-
client.logger.error(subtask.to_s) { e.message }
55+
client.logger.error(subtask.to_s) { e.message + "\n\t" + e.backtrace.join("\n\t") }
5456
end
5557

5658
@restart.wait
@@ -115,8 +117,8 @@ def build_ssl_context
115117
end
116118

117119
def build_endpoint
118-
endpoint = ::Async::IO::Endpoint.tcp(addr, port)
119-
endpoint = ::Async::IO::SSLEndpoint.new(endpoint, ssl_context: build_ssl_context) if secure?
120+
endpoint = ::IO::Endpoint.tcp(addr, port)
121+
endpoint = ::IO::Endpoint::SSLEndpoint.new(endpoint, ssl_context: build_ssl_context) if secure?
120122
endpoint
121123
end
122124

@@ -134,9 +136,9 @@ def connect
134136
end
135137
end
136138

137-
if Gem::Version.new(Async::WebSocket::VERSION) >= Gem::Version.new('0.9.0')
139+
if Gem::Version.new(Async::WebSocket::VERSION) < Gem::Version.new('0.9.0')
138140
raise(
139141
"Incompatible version of async-websocket, #{Async::WebSocket::VERSION}, " \
140-
"use \"gem 'async-websocket', '~> 0.8.0'\"."
142+
"use the latest \"gem 'async-websocket'\" and \"gem 'io-endpoint'\"."
141143
)
142144
end

0 commit comments

Comments
 (0)