em-hyperdex-client 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. data/lib/em-hyperdex-client.rb +39 -24
  2. metadata +3 -3
@@ -7,6 +7,7 @@ module EM::HyperDex; end
7
7
  class EM::HyperDex::Client
8
8
  def initialize(host, port)
9
9
  @client = HyperDex::Client::Client.new(host, port)
10
+ @failed = false
10
11
  @outstanding = {}
11
12
 
12
13
  if ::EM.reactor_running?
@@ -27,6 +28,12 @@ class EM::HyperDex::Client
27
28
  define_method(m) do |*args, &block|
28
29
  df = ::EM::DefaultDeferrable.new
29
30
 
31
+ if @failed
32
+ return df.tap do |df|
33
+ df.fail(RuntimeError.new("This client has failed. Please open a new one."))
34
+ end
35
+ end
36
+
30
37
  begin
31
38
  if ::EM.reactor_running?
32
39
  @outstanding[@client.__send__(hyperdex_method, *args)] = df
@@ -45,6 +52,12 @@ class EM::HyperDex::Client
45
52
 
46
53
  ITERATOR_METHODS.each do |m|
47
54
  define_method(m) do |*args, &block|
55
+ if @failed
56
+ return ::EM::DefaultDeferrable.new.tap do |df|
57
+ df.fail(RuntimeError.new("This client has failed. Please open a new one."))
58
+ end
59
+ end
60
+
48
61
  iter = @client.__send__(m, *args)
49
62
  df = DeferrableEnumerable.new(iter)
50
63
  df.callback(&block) if block_given?
@@ -59,19 +72,25 @@ class EM::HyperDex::Client
59
72
 
60
73
  def handle_response
61
74
  begin
62
- df = @client.method(:loop).arity == 0 ?
63
- @outstanding.delete(op = @client.loop) :
64
- @outstanding.delete(op = @client.loop(0))
65
-
66
- # It's possible for the client's poll_fd to see activity when there
67
- # isn't any new completed operation; according to rescrv, this can
68
- # happen "because of background activity". In that case, `#loop`
69
- # called with a timeout will return `nil`, and we should just
70
- # return quietly.
71
- if op.nil?
72
- return
73
- end
75
+ df = @outstanding.delete(op = @client.loop(0))
76
+ rescue HyperDex::Client::HyperDexClientException
77
+ # Something has gone wrong, and we're just going to take our bat
78
+ # and ball and go home.
79
+ @outstanding.values.each { |op| op.fail(ex) }
80
+ @failed = true
81
+ return
82
+ end
74
83
 
84
+ # It's possible for the client's poll_fd to see activity when there
85
+ # isn't any new completed operation; according to rescrv, this can
86
+ # happen "because of background activity". In that case, `#loop`
87
+ # called with a timeout will return `nil`, and we should just
88
+ # return quietly.
89
+ if op.nil?
90
+ return
91
+ end
92
+
93
+ begin
75
94
  if df.respond_to?(:item_available)
76
95
  df.item_available
77
96
  else
@@ -113,19 +132,15 @@ class EM::HyperDex::Client
113
132
  end
114
133
 
115
134
  def item_available
116
- begin
117
- val = @iter.next
118
- if val.nil?
119
- succeed
120
- else
121
- begin
122
- @each_block.call(val)
123
- rescue Exception => ex
124
- fail(ex)
125
- end
135
+ val = @iter.next
136
+ if val.nil?
137
+ succeed
138
+ else
139
+ begin
140
+ @each_block.call(val)
141
+ rescue Exception => ex
142
+ fail(ex)
126
143
  end
127
- rescue HyperDex::Client::HyperDexClientException => ex
128
- fail(ex)
129
144
  end
130
145
  end
131
146
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-hyperdex-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -248,7 +248,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
248
  version: '0'
249
249
  segments:
250
250
  - 0
251
- hash: 3535170018174481351
251
+ hash: -1903398093042256464
252
252
  required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  none: false
254
254
  requirements:
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  version: '0'
258
258
  segments:
259
259
  - 0
260
- hash: 3535170018174481351
260
+ hash: -1903398093042256464
261
261
  requirements: []
262
262
  rubyforge_project:
263
263
  rubygems_version: 1.8.23