opal-drb 0.4.0 → 0.4.1

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
  SHA256:
3
- metadata.gz: 31f25d589721b4fd2c8e0369f9670d3582f09bc05ed356a9981d592584a255d7
4
- data.tar.gz: 3b8019bd1301893dff9835b1c0b97c498923a02b76d157b96ef6eeba46bfe1da
3
+ metadata.gz: 54baa5953deb2f759b8ddeabe50f9e0d7f3e2e7c69fbb446b208ed59514f11c1
4
+ data.tar.gz: 87cb35cfb700ade0d9fb180def4811628494a4eb9fc32ee40f7f30e29e39d247
5
5
  SHA512:
6
- metadata.gz: f0a15f23039a6c46d313ea3b0a3a96473956d2b072b87619195d53d7b8fb5bf2348ed54c04863a358ac306b5124ca7a918e958f61fd07ae3fb90e93d8e858bea
7
- data.tar.gz: 0262cde7ac7f3681fd067bc72e630692393d305aca8d246045a66470f7ae78c9b926f4509f8e7ee70d8910dd95c807af9051aa0bf103a4eb8be737b81e68f85a
6
+ metadata.gz: dcadd165c9f20a2c80ede70c7d3b95bbed9799730aa1be91f9d9b3d3123375abe4650c002d6415f4d19a17a39a6eadd3009f3c55a8d07f2d087c0f7f1cbeefa7
7
+ data.tar.gz: 2e518ce27d32546f4593fb9ba0ef3da705748df6d6f1766494d54822ab248e8e5b80b4029be522309005054cd5361441f7e35568d35ae943a3c6b0f4d669fb44
@@ -39,7 +39,7 @@ module DRb
39
39
 
40
40
  def send_message(ref, msg_id, arg, b, &callback)
41
41
  @protocol.send_request(ref, msg_id, arg, b).then do |stream|
42
- yield @protocol.recv_reply stream
42
+ callback.call(@protocol.recv_reply(stream))
43
43
  end
44
44
  end
45
45
 
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module DRb
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
@@ -90,6 +90,14 @@ module DRb
90
90
  def initialize(uri, ws)
91
91
  @uri = uri
92
92
  @ws = ws
93
+ @handlers = {}
94
+
95
+ ws.onmessage do |event|
96
+ message_data = event.data.to_s
97
+ sender_id = message_data.slice(0, 36)
98
+ message = message_data.slice(36, message_data.length - 36)
99
+ @handlers.delete(sender_id).call(message)
100
+ end
93
101
  end
94
102
 
95
103
  def self.open(uri)
@@ -107,6 +115,21 @@ module DRb
107
115
  self.new(uri, ws)
108
116
  end
109
117
 
118
+ def send(data, &block)
119
+ sender_id = SecureRandom.uuid
120
+ @handlers[sender_id] = block
121
+ byte_data = sender_id.bytes.each_slice(2).map(&:first)
122
+ byte_data += data.bytes.each_slice(2).map(&:first)
123
+
124
+ if @ws.connecting?
125
+ @ws.onopen do
126
+ @ws.send(`new Uint8Array(#{byte_data}).buffer`)
127
+ end
128
+ else
129
+ @ws.send(`new Uint8Array(#{byte_data}).buffer`)
130
+ end
131
+ end
132
+
110
133
  def [](uri)
111
134
  @sockets[uri].ws
112
135
  end
@@ -201,7 +224,6 @@ module DRb
201
224
  @config = config
202
225
  @msg = DRbMessage.new(@config)
203
226
  @req_stream = stream
204
- @sender_id = SecureRandom.uuid
205
227
  end
206
228
 
207
229
  def close
@@ -237,7 +259,6 @@ module DRb
237
259
  @res = nil
238
260
  @config = config
239
261
  @msg = DRbMessage.new(@config)
240
- @sender_id = SecureRandom.uuid
241
262
  end
242
263
 
243
264
  def alive?
@@ -259,15 +280,7 @@ module DRb
259
280
 
260
281
  def send(uri, data)
261
282
  promise = Promise.new
262
- event_handler = Proc.new do |event|
263
- message_data = event.data.to_s
264
- sender_id = message_data.slice(0, 36)
265
- message = message_data.slice(36, message_data.length - 36)
266
-
267
- unless sender_id == @sender_id
268
- next
269
- end
270
-
283
+ @pool.send(data) do |message|
271
284
  reply_stream = StrStream.new
272
285
  reply_stream.write(message.to_s)
273
286
 
@@ -276,20 +289,7 @@ module DRb
276
289
  end
277
290
 
278
291
  promise.resolve reply_stream
279
- @pool.ws.off(event_handler)
280
292
  end
281
- @pool.ws.onmessage(&event_handler)
282
- byte_data = @sender_id.bytes.each_slice(2).map(&:first)
283
- byte_data += data.bytes.each_slice(2).map(&:first)
284
-
285
- if @pool.ws.connecting?
286
- @pool.ws.onopen do
287
- @pool.ws.send(`new Uint8Array(#{byte_data}).buffer`)
288
- end
289
- else
290
- @pool.ws.send(`new Uint8Array(#{byte_data}).buffer`)
291
- end
292
-
293
293
  promise
294
294
  end
295
295
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-drb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - youchan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-19 00:00:00.000000000 Z
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -119,8 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.7.6
122
+ rubygems_version: 3.0.1
124
123
  signing_key:
125
124
  specification_version: 4
126
125
  summary: A dRuby implementation for Opal