ws_client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 623fede1a088f4f9ebdea245aa16ce11fc3a82e8
4
- data.tar.gz: 45a531ee91368609cda816b4316569ee54a69dbb
3
+ metadata.gz: d6c418fc7b686210fc3ea7d779fa8953b7990209
4
+ data.tar.gz: a0843638a3b961aba33b3c89bf35add83a110c58
5
5
  SHA512:
6
- metadata.gz: 6983cc6b405ef101c3ede5e27ea194982b4722f73ef6b0b15ad4bae796598026968366ee4abf4ad102441b622f18bc4a25bbd181d9a307144e9449ff695d11ac
7
- data.tar.gz: 8b6471536121d3c270187cb4e8f541e059e2382da4dd54582c92943b42e9fe4e890485966d41ce9f8b1dac92b3a9d3578efc83c3fb7eaf4966bb409b21fb044b
6
+ metadata.gz: 717b41e9d41803e667c625b9f2b372db5e9cc8bb078176dfc801c0088f77cae419a7bf5917c3aba53a6bcdd32bccd50758a1b21ac303efe0d0c8e931bdcd7dad
7
+ data.tar.gz: c97d5e0c0fe34c5ca963afbef21b59dcb6a086826fc1ca4035c224e750f0884bee79a1521876016ae2d44b51d3da44f2b91eaca92bee024eeee35c557ea7d027
data/lib/ws_client.rb CHANGED
@@ -62,13 +62,8 @@ module WsClient
62
62
  connect(nil)
63
63
  end
64
64
 
65
- def send_data(data, opt={:type => :text})
66
- @thread ||= poll # utilize the polling interface, could probably be split into another class
67
- write_data(data, opt)
68
- end
69
-
70
65
  # Returns all responses that have been accepted
71
- def send_data_and_wait(data, timeout, opt = { :type => :text })
66
+ def send_data_and_wait(data, timeout = MS_2, opt = { :type => :text })
72
67
  response_data = []
73
68
  write_data(data, opt)
74
69
  pull_next_message_off_of_socket(@socket, timeout)
@@ -82,6 +77,7 @@ module WsClient
82
77
 
83
78
  response_data
84
79
  end
80
+ alias_method :send_data, :send_data_and_wait
85
81
 
86
82
  def close
87
83
  return if @closed
@@ -92,7 +88,6 @@ module WsClient
92
88
  @closed = true
93
89
  @socket.close if @socket
94
90
  @socket = nil
95
- Thread.kill @thread if @thread
96
91
  end
97
92
 
98
93
  def closed?
@@ -134,18 +129,6 @@ module WsClient
134
129
  emit :open if @handshaked
135
130
  end
136
131
 
137
- def poll
138
- return Thread.new(@socket) do |socket|
139
- while !@closed do
140
- pull_next_message_off_of_socket(socket)
141
-
142
- message_queue.length.times do
143
- emit :message, message_queue.pop
144
- end
145
- end
146
- end
147
- end
148
-
149
132
  def pull_next_message_off_of_socket(socket, timeout = 10, last_frame = nil)
150
133
  read_sockets, _, _ = IO.select([socket], nil, nil, timeout)
151
134
 
@@ -204,4 +187,29 @@ module WsClient
204
187
  end
205
188
  end
206
189
  end
190
+
191
+ class AsyncClient < ::WsClient::Client
192
+ def close
193
+ super
194
+ ensure
195
+ Thread.kill @thread if @thread
196
+ end
197
+
198
+ def send_data(data, opt={:type => :text})
199
+ @thread ||= poll # utilize the polling interface, could probably be split into another class
200
+ write_data(data, opt)
201
+ end
202
+
203
+ def poll
204
+ return Thread.new(@socket) do |socket|
205
+ while !@closed do
206
+ pull_next_message_off_of_socket(socket)
207
+
208
+ message_queue.length.times do
209
+ emit :message, message_queue.pop
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
207
215
  end
@@ -1,3 +1,3 @@
1
1
  module WsClient
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ws_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dewitt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-08-12 00:00:00.000000000 Z
12
+ date: 2016-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler