elementary-rpc 2.0.1 → 2.1.0

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: 01d8929a493192dbf8c12d6d5046dbe3f774ef27
4
- data.tar.gz: 1cb9f7bce35278ca545912ff9e6e16ea42831aef
3
+ metadata.gz: 951183ca8f8f757c71cc4cd5206493cc1b73bc2e
4
+ data.tar.gz: f89d260dd17f4e1bb452096afa7d2b0eeb764074
5
5
  SHA512:
6
- metadata.gz: 8ee48e01fe3789e12c364396ffebfb6df086c498bd3f993506991e7c9dfb222c5ab117aa2752ceda7f73c5ef4c767753ae631cdfbf56d3e2d14074eccd2cbf3f
7
- data.tar.gz: d891ab7b2dae7b0971e76521b55327620dce0db5ddf0ea8ac516c777a270d0083d45bf1c21ceb3d7085df16e79d6736337620e3eb2f04b0992e053d842429b74
6
+ metadata.gz: 59d917f23f7c39763e7b5ae6a1d799d2edd775a5eaad42e8efac697337df8cf7c186928054e143fd61f01f30d5eb20b229287704af201486171e590507ca7aea
7
+ data.tar.gz: d29d542247d5f83e6adb0d9469a85a3e8096df72c5aed5606d7762ba5d0dc3cde58c09340835348ab5b01d4a309f5ef0d3b2ac691999553c79ae1fa6d8bf89c6
data/.gitignore CHANGED
@@ -22,3 +22,5 @@ tmp
22
22
  mkmf.log
23
23
  *.swp
24
24
  .ruby-*
25
+ .idea
26
+ *.iml
@@ -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
@@ -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:
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Elementary
3
- VERSION = "2.0.1"
3
+ VERSION = "2.1.0"
4
4
  end
@@ -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.1
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-03 00:00:00.000000000 Z
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