elementary-rpc 2.0.1 → 2.1.0
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 +4 -4
- data/.gitignore +2 -0
- data/lib/elementary/connection.rb +5 -1
- data/lib/elementary/executor.rb +3 -2
- data/lib/elementary/version.rb +1 -1
- data/spec/connection_spec.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 951183ca8f8f757c71cc4cd5206493cc1b73bc2e
|
4
|
+
data.tar.gz: f89d260dd17f4e1bb452096afa7d2b0eeb764074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59d917f23f7c39763e7b5ae6a1d799d2edd775a5eaad42e8efac697337df8cf7c186928054e143fd61f01f30d5eb20b229287704af201486171e590507ca7aea
|
7
|
+
data.tar.gz: d29d542247d5f83e6adb0d9469a85a3e8096df72c5aed5606d7762ba5d0dc3cde58c09340835348ab5b01d4a309f5ef0d3b2ac691999553c79ae1fa6d8bf89c6
|
data/.gitignore
CHANGED
@@ -22,6 +22,9 @@ module Elementary
|
|
22
22
|
# @option opts [Hash] :transport_options A +Hash+ of request options that
|
23
23
|
# will be passed down to the transport layer. This will depend on what
|
24
24
|
# options are available by the underlying transport
|
25
|
+
# @option opts [Hash] :future_options A +Hash+ of options to use when
|
26
|
+
# constructing the Concurrent::Future to run the RPC. In particular, it
|
27
|
+
# allows specifying the :executor for the Concurrent::Future.
|
25
28
|
def initialize(service, opts={})
|
26
29
|
opts = Hashie::Mash.new(opts)
|
27
30
|
|
@@ -34,10 +37,11 @@ module Elementary
|
|
34
37
|
@transport = opts[:transport]
|
35
38
|
@hosts = opts[:hosts] || DEFAULT_HOSTS
|
36
39
|
@transport_opts = opts[:transport_options] || {}
|
40
|
+
@future_opts = opts[:future_options] || {}
|
37
41
|
end
|
38
42
|
|
39
43
|
def rpc
|
40
|
-
@rpc ||= Elementary::Executor.new(@service, select_transport)
|
44
|
+
@rpc ||= Elementary::Executor.new(@service, select_transport, @future_opts)
|
41
45
|
end
|
42
46
|
|
43
47
|
def select_transport
|
data/lib/elementary/executor.rb
CHANGED
@@ -3,16 +3,17 @@ module Elementary
|
|
3
3
|
class Executor
|
4
4
|
attr_reader :service, :transport
|
5
5
|
|
6
|
-
def initialize(service, transport)
|
6
|
+
def initialize(service, transport, future_opts={})
|
7
7
|
@service = service
|
8
8
|
@transport = transport
|
9
|
+
@future_opts = future_opts
|
9
10
|
end
|
10
11
|
|
11
12
|
def method_missing(method_name, *params)
|
12
13
|
rpc_method = service.rpcs[method_name.to_sym]
|
13
14
|
# XXX: explode if rpc_method is nil
|
14
15
|
|
15
|
-
future = Elementary::Future.new do
|
16
|
+
future = Elementary::Future.new(@future_opts) do
|
16
17
|
# This is effectively a Rack middleware stack. yay.
|
17
18
|
#
|
18
19
|
# Easiest to think of it like this:
|
data/lib/elementary/version.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -136,6 +136,30 @@ describe Elementary::Connection do
|
|
136
136
|
expect(value.data).to eql('rspec')
|
137
137
|
end
|
138
138
|
end
|
139
|
+
|
140
|
+
context 'with :future_options specifying a Concurrent::Executor' do
|
141
|
+
class MyExecutor < Concurrent::ImmediateExecutor
|
142
|
+
attr_reader :post_count
|
143
|
+
def initialize
|
144
|
+
super
|
145
|
+
@post_count = 0
|
146
|
+
end
|
147
|
+
def post(*args, &task)
|
148
|
+
@post_count = @post_count + 1
|
149
|
+
super
|
150
|
+
end
|
151
|
+
end
|
152
|
+
let(:my_executor) { MyExecutor.new }
|
153
|
+
let(:opts) { { 'hosts' => [{'host' => 'localhost', 'port' => '8000'}],
|
154
|
+
:future_options => { :executor => my_executor } } }
|
155
|
+
subject(:response) { connection.rpc.echo(request) }
|
156
|
+
|
157
|
+
it 'should run on the specified executor' do
|
158
|
+
expect(response).to be_instance_of Elementary::Future
|
159
|
+
response.value # Wait on the future
|
160
|
+
expect(my_executor.post_count).to be 1
|
161
|
+
end
|
162
|
+
end
|
139
163
|
end
|
140
164
|
end
|
141
165
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elementary-rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- R. Tyler Croy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|