volcano-sdk 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee82d4e1a777fcbca79d4ac464ae7ad87d8f0374fb6955cd1e61167a9c82641c
4
- data.tar.gz: fd76dca669566978d588a0c0eb01c38b17166a621ae43f1a0f44862884083fb8
3
+ metadata.gz: 59e652b75cb01f8a353cca787d8e97ecce893091202389d6eb05d16898553fe4
4
+ data.tar.gz: 1aaab53a45bb753db900c0dbb5fe0d95d27c17f36a0bc4487e396a37f10e0a7c
5
5
  SHA512:
6
- metadata.gz: 4ce4ffb6d72500cfaae2736bede0a7438a1bf079a3c5c2e540ebf3bd737eb2157c46c8e08011b4d93a15deb900daf616fe076c64f3e29c3dfc0c08ba2e80acce
7
- data.tar.gz: 8486d6ae8e2fb766e918610389ca94eb98d08446d01a5beebb7002b5a44448508a31681da6100a59ab5f62d4d5b0894fca9072ae09a33914d0c45f9d24f32f03
6
+ metadata.gz: f1c408840aeabf36d2880bb13f8fa9ef602ecb1fa5de7e0b3db936ca48f02ce8b8dc667c6dcf52ec4637f4418f6c9b45bbf157081cbc167406752980d1c56bc2
7
+ data.tar.gz: 641095882ee98d37672f0c7c9a59a2051d98f4a392682df91753b999fffd2aae91a65a62e9c299569f5e1d3c96f73b4095247e168954ae7c75f6e36f5a71fed2
@@ -35,7 +35,7 @@ module Volcano
35
35
  include ProtocolRecoveryPosition
36
36
 
37
37
  Failure = Data.define(:error)
38
- Pending = Data.define(:queue, :on_reply)
38
+ Pending = Data.define(:queue, :on_reply, :reply_key)
39
39
  private_constant :Pending
40
40
  Events = Data.define(:on_close, :on_error, :on_failure)
41
41
  DEFAULT_REQUEST_TIMEOUT = 10
@@ -81,7 +81,7 @@ module Volcano
81
81
  end
82
82
 
83
83
  def connect(token:)
84
- result = request { |id| self.class.connect(id: id, token: token) }
84
+ result = request('connect') { |id| self.class.connect(id: id, token: token) }
85
85
  ensure_open!
86
86
  @connected = true
87
87
  result
@@ -99,20 +99,22 @@ module Volcano
99
99
  end
100
100
  end
101
101
 
102
- def publish(channel:, data:) = request { |id| self.class.publish(id: id, channel: channel, data: data) }
102
+ def publish(channel:, data:)
103
+ request('publish') { |id| self.class.publish(id: id, channel: channel, data: data) }
104
+ end
103
105
 
104
106
  def unsubscribe(channel:)
105
107
  @subscription_lock.acquire do
106
108
  ensure_open!
107
109
  next {} unless @subscriptions.include?(channel)
108
110
 
109
- result = request { |id| self.class.unsubscribe(id: id, channel: channel) }
111
+ result = request('unsubscribe') { |id| self.class.unsubscribe(id: id, channel: channel) }
110
112
  @subscriptions.delete(channel)
111
113
  result
112
114
  end
113
115
  end
114
116
 
115
- def presence(channel:) = request { |id| self.class.presence(id: id, channel: channel) }
117
+ def presence(channel:) = request('presence') { |id| self.class.presence(id: id, channel: channel) }
116
118
 
117
119
  def close
118
120
  return nil if @closed
@@ -30,7 +30,7 @@ module Volcano
30
30
  pending = @pending[frame.fetch('id')]
31
31
  return unless pending
32
32
 
33
- reply = reply_value(frame)
33
+ reply = reply_value(frame, pending.reply_key)
34
34
  pending.queue.enqueue(apply_reply_hook(pending, reply))
35
35
  end
36
36
 
@@ -43,9 +43,9 @@ module Volcano
43
43
  Protocol::Failure.new(error: e)
44
44
  end
45
45
 
46
- def reply_value(frame)
46
+ def reply_value(frame, reply_key)
47
47
  error = frame['error']
48
- return frame['result'] || frame.except('id') unless error
48
+ return frame.fetch(reply_key) { frame.fetch('result') { frame.except('id') } } unless error
49
49
 
50
50
  message = error['message'] || 'realtime command failed'
51
51
  Protocol::Failure.new(error: ServerError.new(message, code: error['code']))
@@ -8,9 +8,9 @@ module Volcano
8
8
  module IO
9
9
  private
10
10
 
11
- def request(on_reply: nil)
11
+ def request(reply_key, on_reply: nil)
12
12
  ensure_open!
13
- id, reply_queue = register_request(on_reply)
13
+ id, reply_queue = register_request(reply_key, on_reply)
14
14
  write_frame(yield(id))
15
15
  reply = await_reply(reply_queue)
16
16
  raise reply.error if reply.is_a?(Failure)
@@ -22,14 +22,14 @@ module Volcano
22
22
  @pending.delete(id) if defined?(id)
23
23
  end
24
24
 
25
- def register_request(on_reply)
25
+ def register_request(reply_key, on_reply)
26
26
  if @pending.length >= @max_pending
27
27
  raise PendingLimitError, "realtime pending command limit #{@max_pending} reached"
28
28
  end
29
29
 
30
30
  @next_id += 1
31
31
  queue = Async::Queue.new
32
- @pending[@next_id] = Pending.new(queue: queue, on_reply: on_reply)
32
+ @pending[@next_id] = Pending.new(queue: queue, on_reply: on_reply, reply_key: reply_key)
33
33
  [@next_id, queue]
34
34
  end
35
35
 
@@ -15,7 +15,7 @@ module Volcano
15
15
  end
16
16
  end
17
17
 
18
- request(on_reply:) do |id|
18
+ request('subscribe', on_reply:) do |id|
19
19
  self.class.subscribe(
20
20
  id: id,
21
21
  channel: channel,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Volcano
4
- VERSION = '0.10.0'
4
+ VERSION = '0.10.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volcano-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kong