ione-rpc 1.0.0 → 1.0.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
  SHA1:
3
- metadata.gz: 518c9857895955f9c26c4be3d3be5d21773c7525
4
- data.tar.gz: 6b6c39ffa664e4b290bb5c0ebaeab462dd8fbb23
3
+ metadata.gz: bd2dfbaf504cd8f90db14054c3f1be44a1bf6740
4
+ data.tar.gz: 4ecca4c71c9d9857c4df03a0caaecf52fb56a973
5
5
  SHA512:
6
- metadata.gz: d3e6c4d47dda87d60ac7034243d0c946af0117bd8fed3b043d23ecbbbc6cb6817253e3b5199bb5967d38b077d51ed40a4991d04de29e93cd7adbb0e12098427e
7
- data.tar.gz: 9f60335dcdb60a2353fcf07684fdd9e9f17715c679253badb1f6415e4e276de67759bfe427392e48266db2216d7a7be3a816dbb2543e6eeb9152e53c702926bb
6
+ metadata.gz: 005b40b386819c5f9ce87398b6456981b996d7d9a82f03aa13db17f64a18db4de9117474261b7a1c7a2cf30117542db425c00165d8a5f99272441f5413ce5c5a
7
+ data.tar.gz: 336273d46b03c7cbcd15f59b2c9f3b46ce8da3de9169b583bbb9f867238af9eff73f4dc9cca227f93aa38409ed5342e1c2dd7a413cc05f37937fa712770b6cc8
data/README.md CHANGED
@@ -10,11 +10,16 @@ Ione RPC is a framework for writing server and client components for your Ruby a
10
10
 
11
11
  # Installing
12
12
 
13
- There is currently no gem release of Ione RPC, but you can install it from git with Bundler:
13
+ Ione RPC is available from [Rubygems](https://rubygems.org) and can be installed with the `gem` command:
14
+
15
+ ```
16
+ $ gem install ione-rpc
17
+ ```
18
+
19
+ but more commonly you will add it to your `Gemfile`:
14
20
 
15
21
  ```ruby
16
- # in Gemfile
17
- gem 'ione-rpc', github: 'iconara/ione-rpc'
22
+ gem 'ione-rpc'
18
23
  ```
19
24
 
20
25
  # Example
@@ -140,7 +145,7 @@ class TranslationClient < Ione::Rpc::Client
140
145
  end
141
146
  ```
142
147
 
143
- If you read the part above about how the client randomly selected which server to talk to and though that that wasn't very useful, there's a way to override that, just implement `#choose_connection`:
148
+ If you read the part above about how the client randomly selected which server to talk to and thought that that wasn't very useful, there's a way to override that, just implement `#choose_connection`:
144
149
 
145
150
  ```ruby
146
151
  class TranslationClient < Ione::Rpc::Client
@@ -141,15 +141,19 @@ module Ione
141
141
  # client (immediately, this is mostly to be consistent with #add_host)
142
142
  def remove_host(hostname, port=nil)
143
143
  hostname, port = normalize_address(hostname, port)
144
+ connection = nil
144
145
  @lock.synchronize do
145
146
  index = @hosts.index { |h, p, _| h == hostname && p == port }
146
147
  if index
147
148
  @hosts.delete_at(index)
148
- if (connection = @connections.find { |c| c.host == hostname && c.port == port })
149
- connection.close
149
+ if (conn = @connections.find { |c| c.host == hostname && c.port == port })
150
+ connection = conn
150
151
  end
151
152
  end
152
153
  end
154
+ if connection
155
+ connection.close
156
+ end
153
157
  Future.resolved(self)
154
158
  end
155
159
 
@@ -39,7 +39,7 @@ module Ione
39
39
  if closed?
40
40
  return Ione::Future.failed(Rpc::RequestNotSentError.new('Connection closed'))
41
41
  end
42
- promise = Ione::Promise.new
42
+ promise = RequestPromise.new
43
43
  channel = nil
44
44
  @lock.lock
45
45
  begin
@@ -60,12 +60,11 @@ module Ione
60
60
  end
61
61
  end
62
62
  if timeout
63
- @scheduler.schedule_timer(timeout).on_value do
64
- unless promise.future.completed?
65
- error = Rpc::TimeoutError.new('No response received within %ss' % timeout.to_s)
66
- promise.fail(error)
67
- @timeouts += 1
68
- end
63
+ promise.timeout_future = @scheduler.schedule_timer(timeout)
64
+ promise.timeout_future.on_value do
65
+ error = Rpc::TimeoutError.new('No response received within %ss' % timeout.to_s)
66
+ promise.fail(error)
67
+ @timeouts += 1
69
68
  end
70
69
  end
71
70
  promise.future
@@ -73,6 +72,10 @@ module Ione
73
72
 
74
73
  private
75
74
 
75
+ class RequestPromise < Promise
76
+ attr_accessor :timeout_future
77
+ end
78
+
76
79
  def handle_message(response, channel)
77
80
  promise = nil
78
81
  @lock.lock
@@ -85,6 +88,7 @@ module Ione
85
88
  end
86
89
  if promise && !promise.future.completed?
87
90
  promise.fulfill(response)
91
+ @scheduler.cancel_timer(promise.timeout_future) if promise.timeout_future
88
92
  end
89
93
  flush_queue
90
94
  end
@@ -133,9 +133,9 @@ module Ione
133
133
  else
134
134
  message = decode_body(state, body)
135
135
  end
136
- return message, state.channel, true
136
+ [message, state.channel, true]
137
137
  else
138
- return state, nil, false
138
+ [state, nil, false]
139
139
  end
140
140
  end
141
141
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ione
4
4
  module Rpc
5
- VERSION = '1.0.0'.freeze
5
+ VERSION = '1.0.1'.freeze
6
6
  end
7
7
  end
@@ -53,6 +53,9 @@ module Ione
53
53
  timer_promises << Promise.new
54
54
  timer_promises.last.future
55
55
  end
56
+ scheduler.stub(:cancel_timer) do |timer|
57
+ timer_promises.delete(timer)
58
+ end
56
59
  scheduler.stub(:timer_promises).and_return(timer_promises)
57
60
  end
58
61
 
@@ -146,6 +149,13 @@ module Ione
146
149
  expect { f.value }.to_not raise_error
147
150
  end
148
151
 
152
+ it 'cancel the timeout timer when the response is received before the timeout passes' do
153
+ f = peer.send_message('foo', 2)
154
+ connection.data_listener.call('bar@000')
155
+ scheduler.timer_promises.first.fulfill
156
+ scheduler.should have_received(:cancel_timer).once
157
+ end
158
+
149
159
  it 'fails the request when the connection is closed' do
150
160
  connection.stub(:closed?).and_return(true)
151
161
  f = peer.send_message('foo', 2)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ione-rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Hultberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-21 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ione
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '1.2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '1.2'
27
33
  description: A toolkit for building RPC layers using Ione
28
34
  email:
29
35
  - theo@iconara.net