libuv 0.12.2 → 0.12.3

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: eeeff8f0622e2ab797a7a2687e12b5c5bd8ee677
4
- data.tar.gz: a451d8e71e0249ed03941f78dc87cd3cf9cd3313
3
+ metadata.gz: 926a9cc1569e2c71b0881c94d233cbd35bf92f26
4
+ data.tar.gz: 945117ade8eac5e366c0d073660ef45e4f317648
5
5
  SHA512:
6
- metadata.gz: 071316fc01a0486e4d3dfba8544a2ff1f9681b653622beff3e756b26301e068ba7c55d13fb204d542b0a8791d2ce408ed23b2eca04105126059f6b05a6b671d5
7
- data.tar.gz: 05b5e1d5199578c27f4e7170c5dedf86d6e50f1b872c0e101f3ee5ea16eb5a1734591541f5758de25c6ac1f20b61ded85162d5124a60f078ba229414f68f871a
6
+ metadata.gz: ab328f0f71c9d038cf7f64efecd094eac250c3713faa5f7320de71e0dda8f2c92dcb98d5ddcf5f779adcf5f8bf1be7fac0f3fc818b9517509d2944243bf81fa3
7
+ data.tar.gz: 5e2a9f0b8ad7f488bbfb3def370fa6e5a4617c93ca77619dc94f8411b428386924143da52dc6e5280c63f215440316675a823ca1c2421745fa473813f81040e9
data/lib/libuv/async.rb CHANGED
@@ -30,17 +30,11 @@ module Libuv
30
30
  private
31
31
 
32
32
 
33
- def on_async(handle, status)
34
- e = check_result(status)
35
-
36
- if e
37
- reject(e)
38
- else
39
- begin
40
- @callback.call
41
- rescue Exception => e
42
- @loop.log :error, :async_cb, e
43
- end
33
+ def on_async(handle)
34
+ begin
35
+ @callback.call
36
+ rescue Exception => e
37
+ @loop.log :error, :async_cb, e
44
38
  end
45
39
  end
46
40
  end
data/lib/libuv/check.rb CHANGED
@@ -39,17 +39,11 @@ module Libuv
39
39
  private
40
40
 
41
41
 
42
- def on_check(handle, status)
43
- e = check_result(status)
44
-
45
- if e
46
- reject(e)
47
- else
48
- begin
49
- @callback.call
50
- rescue Exception => e
51
- @loop.log :error, :check_cb, e
52
- end
42
+ def on_check(handle)
43
+ begin
44
+ @callback.call
45
+ rescue Exception => e
46
+ @loop.log :error, :check_cb, e
53
47
  end
54
48
  end
55
49
  end
data/lib/libuv/error.rb CHANGED
@@ -65,6 +65,7 @@ module Libuv
65
65
  class EPROTOTYPE < Error; end
66
66
  class ERANGE < Error; end
67
67
  class ENXIO < Error; end
68
+ class EMLINK < Error; end
68
69
  class EROFS < Error; end
69
70
  class ESHUTDOWN < Error; end
70
71
  class ESPIPE < Error; end
@@ -219,12 +219,12 @@ module Libuv
219
219
  callback :uv_connection_cb, [:uv_stream_t, :status], :void
220
220
  callback :uv_close_cb, [:uv_handle_t], :void
221
221
  callback :uv_poll_cb, [:uv_poll_t, :status, :events], :void
222
- callback :uv_timer_cb, [:uv_timer_t, :status], :void
222
+ callback :uv_timer_cb, [:uv_timer_t], :void
223
223
  callback :uv_signal_cb, [:uv_signal_t, :signal], :void
224
- callback :uv_async_cb, [:uv_async_t, :status], :void
225
- callback :uv_prepare_cb, [:uv_prepare_t, :status], :void
226
- callback :uv_check_cb, [:uv_check_t, :status], :void
227
- callback :uv_idle_cb, [:uv_idle_t, :status], :void
224
+ callback :uv_async_cb, [:uv_async_t], :void
225
+ callback :uv_prepare_cb, [:uv_prepare_t], :void
226
+ callback :uv_check_cb, [:uv_check_t], :void
227
+ callback :uv_idle_cb, [:uv_idle_t], :void
228
228
  callback :uv_getaddrinfo_cb, [:uv_getaddrinfo_t, :status, UvAddrinfo.by_ref], :void
229
229
  callback :uv_exit_cb, [:uv_process_t, :int, :int], :void
230
230
  callback :uv_walk_cb, [:uv_handle_t, :pointer], :void
data/lib/libuv/idle.rb CHANGED
@@ -39,17 +39,11 @@ module Libuv
39
39
  private
40
40
 
41
41
 
42
- def on_idle(handle, status)
43
- e = check_result(status)
44
-
45
- if e
46
- reject(e)
47
- else
48
- begin
49
- @callback.call
50
- rescue Exception => e
51
- @loop.log :error, :idle_cb, e
52
- end
42
+ def on_idle(handle)
43
+ begin
44
+ @callback.call
45
+ rescue Exception => e
46
+ @loop.log :error, :idle_cb, e
53
47
  end
54
48
  end
55
49
  end
data/lib/libuv/loop.rb CHANGED
@@ -97,6 +97,13 @@ module Libuv
97
97
  public
98
98
 
99
99
 
100
+ # Overwrite as errors in jRuby can literally hang VM when inspecting
101
+ # as many many classes will reference this class
102
+ def inspect
103
+ "#<#{self.class}:0x#{self.__id__.to_s(16)} NT=#{@run_queue.length}>"
104
+ end
105
+
106
+
100
107
  def handle; @pointer; end
101
108
 
102
109
  # Run the actual event loop. This method will block until the loop is stopped.
@@ -193,12 +200,17 @@ module Libuv
193
200
  # @return [::Libuv::Error]
194
201
  def lookup_error(err)
195
202
  name = ::Libuv::Ext.err_name(err)
196
- msg = ::Libuv::Ext.strerror(err)
197
203
 
198
- ::Libuv::Error.const_get(name.to_sym).new(msg)
204
+ if name
205
+ msg = ::Libuv::Ext.strerror(err)
206
+ ::Libuv::Error.const_get(name.to_sym).new(msg)
207
+ else
208
+ # We want a back-trace in this case
209
+ raise "error lookup failed for code #{err}"
210
+ end
199
211
  rescue Exception => e
200
212
  @loop.log :warn, :error_lookup_failed, e
201
- ::Libuv::Error::UNKNOWN.new("error lookup failed for code #{err} #{name} #{msg}")
213
+ e
202
214
  end
203
215
 
204
216
  # Get a new TCP instance
data/lib/libuv/prepare.rb CHANGED
@@ -39,17 +39,11 @@ module Libuv
39
39
  private
40
40
 
41
41
 
42
- def on_prepare(handle, status)
43
- e = check_result(status)
44
-
45
- if e
46
- reject(e)
47
- else
48
- begin
49
- @callback.call
50
- rescue Exception => e
51
- @loop.log :error, :prepare_cb, e
52
- end
42
+ def on_prepare(handle)
43
+ begin
44
+ @callback.call
45
+ rescue Exception => e
46
+ @loop.log :error, :prepare_cb, e
53
47
  end
54
48
  end
55
49
  end
data/lib/libuv/q.rb CHANGED
@@ -1,454 +1,463 @@
1
1
 
2
2
  module Libuv
3
- module Q
3
+ module Q
4
4
 
5
- # @abstract
6
- class Promise
7
- private_class_method :new
5
+ # @abstract
6
+ class Promise
7
+ private_class_method :new
8
8
 
9
9
 
10
- # Used by finally method
11
- MAKE_PROMISE = proc { |value, resolved, loop|
12
- result = Q.defer(loop)
13
- if (resolved)
14
- result.resolve(value)
15
- else
16
- result.reject(value)
17
- end
18
- result.promise
19
- }.freeze
10
+ # Used by finally method
11
+ MAKE_PROMISE = proc { |value, resolved, loop|
12
+ result = Q.defer(loop)
13
+ if (resolved)
14
+ result.resolve(value)
15
+ else
16
+ result.reject(value)
17
+ end
18
+ result.promise
19
+ }.freeze
20
20
 
21
21
 
22
- #
23
- # regardless of when the promise was or will be resolved / rejected, calls
24
- # the error callback asynchronously if the promise is rejected.
25
- #
26
- # @param [Proc, &blk] callbacks error, error_block
27
- # @return [Promise] Returns an unresolved promise for chaining
28
- def catch(callback = nil, &blk)
29
- self.then(nil, callback || blk)
30
- end
22
+ #
23
+ # regardless of when the promise was or will be resolved / rejected, calls
24
+ # the error callback asynchronously if the promise is rejected.
25
+ #
26
+ # @param [Proc, &blk] callbacks error, error_block
27
+ # @return [Promise] Returns an unresolved promise for chaining
28
+ def catch(callback = nil, &blk)
29
+ self.then(nil, callback || blk)
30
+ end
31
31
 
32
32
 
33
- def progress(callback = nil, &blk)
34
- self.then(nil, nil, callback || blk)
35
- end
33
+ def progress(callback = nil, &blk)
34
+ self.then(nil, nil, callback || blk)
35
+ end
36
36
 
37
37
 
38
- #
39
- # allows you to observe either the fulfillment or rejection of a promise, but to do so
40
- # without modifying the final value. This is useful to release resources or do some
41
- # clean-up that needs to be done whether the promise was rejected or resolved.
42
- #
43
- # @param [Proc, &blk] callbacks finally, finally_block
44
- # @return [Promise] Returns an unresolved promise for chaining
45
- def finally(callback = nil, &blk)
46
- callback ||= blk
38
+ #
39
+ # allows you to observe either the fulfillment or rejection of a promise, but to do so
40
+ # without modifying the final value. This is useful to release resources or do some
41
+ # clean-up that needs to be done whether the promise was rejected or resolved.
42
+ #
43
+ # @param [Proc, &blk] callbacks finally, finally_block
44
+ # @return [Promise] Returns an unresolved promise for chaining
45
+ def finally(callback = nil, &blk)
46
+ callback ||= blk
47
47
 
48
- handleCallback = lambda {|value, isResolved|
49
- callbackOutput = nil
50
- begin
51
- callbackOutput = callback.call
52
- rescue Exception => e
53
- @loop.log(:error, :q_finally_cb, e)
54
- return MAKE_PROMISE.call(e, false, @loop)
55
- end
48
+ handleCallback = lambda {|value, isResolved|
49
+ callbackOutput = nil
50
+ begin
51
+ callbackOutput = callback.call
52
+ rescue Exception => e
53
+ @loop.log(:error, :q_finally_cb, e)
54
+ return MAKE_PROMISE.call(e, false, @loop)
55
+ end
56
56
 
57
- if callbackOutput.is_a?(Promise)
58
- return callbackOutput.then(proc {
59
- MAKE_PROMISE.call(value, isResolved, @loop)
60
- }, proc { |err|
61
- MAKE_PROMISE.call(err, false, @loop)
62
- })
63
- else
64
- return MAKE_PROMISE.call(value, isResolved, @loop)
65
- end
66
- }
57
+ if callbackOutput.is_a?(Promise)
58
+ return callbackOutput.then(proc {
59
+ MAKE_PROMISE.call(value, isResolved, @loop)
60
+ }, proc { |err|
61
+ MAKE_PROMISE.call(err, false, @loop)
62
+ })
63
+ else
64
+ return MAKE_PROMISE.call(value, isResolved, @loop)
65
+ end
66
+ }
67
67
 
68
- self.then(proc {|val|
69
- handleCallback.call(val, true)
70
- }, proc{|err|
71
- handleCallback.call(err, false)
72
- })
73
- end
74
- end
75
-
76
-
77
- #
78
- # A new promise instance is created when a deferred instance is created and can be
79
- # retrieved by calling deferred.promise
80
- #
81
- class DeferredPromise < Promise
82
- public_class_method :new
83
-
84
- def initialize(loop, defer)
85
- raise ArgumentError unless defer.is_a?(Deferred)
86
- super()
87
-
88
- @loop = loop
89
- @defer = defer
90
- end
91
-
92
- #
93
- # regardless of when the promise was or will be resolved / rejected, calls one of
94
- # the success or error callbacks asynchronously as soon as the result is available.
95
- # The callbacks are called with a single argument, the result or rejection reason.
96
- #
97
- # @param [Proc, Proc, Proc, &blk] callbacks error, success, progress, success_block
98
- # @return [Promise] Returns an unresolved promise for chaining
99
- def then(callback = nil, errback = nil, progback = nil, &blk)
100
- result = Q.defer(@loop)
101
-
102
- callback ||= blk
103
-
104
- wrappedCallback = proc { |val|
105
- begin
106
- result.resolve(callback.nil? ? val : callback.call(val))
107
- rescue Exception => e
108
- #warn "\nUnhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
109
- result.reject(e)
110
- @loop.log(:error, :q_resolve_cb, e)
111
- end
112
- }
113
-
114
- wrappedErrback = proc { |reason|
115
- begin
116
- result.resolve(errback.nil? ? Q.reject(@loop, reason) : errback.call(reason))
117
- rescue Exception => e
118
- #warn "Unhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
119
- result.reject(e)
120
- @loop.log(:error, :q_reject_cb, e)
121
- end
122
- }
68
+ self.then(proc {|val|
69
+ handleCallback.call(val, true)
70
+ }, proc{|err|
71
+ handleCallback.call(err, false)
72
+ })
73
+ end
74
+ end
75
+
76
+
77
+ #
78
+ # A new promise instance is created when a deferred instance is created and can be
79
+ # retrieved by calling deferred.promise
80
+ #
81
+ class DeferredPromise < Promise
82
+ public_class_method :new
83
+
84
+ def initialize(loop, defer)
85
+ raise ArgumentError unless defer.is_a?(Deferred)
86
+ super()
87
+
88
+ @loop = loop
89
+ @defer = defer
90
+ end
91
+
92
+ #
93
+ # regardless of when the promise was or will be resolved / rejected, calls one of
94
+ # the success or error callbacks asynchronously as soon as the result is available.
95
+ # The callbacks are called with a single argument, the result or rejection reason.
96
+ #
97
+ # @param [Proc, Proc, Proc, &blk] callbacks error, success, progress, success_block
98
+ # @return [Promise] Returns an unresolved promise for chaining
99
+ def then(callback = nil, errback = nil, progback = nil, &blk)
100
+ result = Q.defer(@loop)
101
+
102
+ callback ||= blk
103
+
104
+ wrappedCallback = proc { |val|
105
+ begin
106
+ result.resolve(callback.nil? ? val : callback.call(val))
107
+ rescue Exception => e
108
+ #warn "\nUnhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
109
+ result.reject(e)
110
+ @loop.log(:error, :q_resolve_cb, e)
111
+ end
112
+ }
113
+
114
+ wrappedErrback = proc { |reason|
115
+ begin
116
+ result.resolve(errback.nil? ? Q.reject(@loop, reason) : errback.call(reason))
117
+ rescue Exception => e
118
+ #warn "Unhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
119
+ result.reject(e)
120
+ @loop.log(:error, :q_reject_cb, e)
121
+ end
122
+ }
123
123
 
124
- wrappedProgback = proc { |*progress|
125
- begin
126
- result.notify(progback.nil? ? progress : progback.call(*progress))
127
- rescue Exception => e
128
- #warn "Unhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
129
- @loop.log(:error, :q_progress_cb, e)
130
- end
131
- }
132
-
133
- #
134
- # Schedule as we are touching shared state
135
- # Everything else is locally scoped
136
- #
137
- @loop.schedule do
138
- pending_array = pending
139
-
140
- if pending_array.nil?
141
- value.then(wrappedCallback, wrappedErrback, wrappedProgback)
142
- else
143
- pending_array << [wrappedCallback, wrappedErrback, wrappedProgback]
144
- end
145
- end
146
-
147
- result.promise
148
- end
124
+ wrappedProgback = proc { |*progress|
125
+ begin
126
+ result.notify(progback.nil? ? progress : progback.call(*progress))
127
+ rescue Exception => e
128
+ #warn "Unhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
129
+ @loop.log(:error, :q_progress_cb, e)
130
+ end
131
+ }
132
+
133
+ #
134
+ # Schedule as we are touching shared state
135
+ # Everything else is locally scoped
136
+ #
137
+ @loop.schedule do
138
+ pending_array = pending
139
+
140
+ if pending_array.nil?
141
+ value.then(wrappedCallback, wrappedErrback, wrappedProgback)
142
+ else
143
+ pending_array << [wrappedCallback, wrappedErrback, wrappedProgback]
144
+ end
145
+ end
146
+
147
+ result.promise
148
+ end
149
149
 
150
- def resolved?
151
- pending.nil?
152
- end
153
-
154
-
155
- private
156
-
157
-
158
- def pending
159
- @defer.instance_eval { @pending }
160
- end
161
-
162
- def value
163
- @defer.instance_eval { @value }
164
- end
165
- end
166
-
167
-
168
-
169
- class ResolvedPromise < Promise
170
- public_class_method :new
171
-
172
- def initialize(loop, response, error = false)
173
- raise ArgumentError if error && response.is_a?(Promise)
174
- super()
175
-
176
- @loop = loop
177
- @error = error
178
- @response = response
179
- end
180
-
181
- def then(callback = nil, errback = nil, progback = nil, &blk)
182
- result = Q.defer(@loop)
183
-
184
- callback ||= blk
185
-
186
- @loop.next_tick {
187
- if @error
188
- begin
189
- result.resolve(errback.nil? ? Q.reject(@loop, @response) : errback.call(@response))
190
- rescue Exception => e
191
- #warn "Unhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
192
- result.reject(e)
193
- @loop.log(:error, :q_reject_cb, e)
194
- end
195
- else
196
- begin
197
- result.resolve(callback.nil? ? @response : callback.call(@response))
198
- rescue Exception => e
199
- #warn "\nUnhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
200
- result.reject(e)
201
- @loop.log(:error, :q_resolve_cb, e)
202
- end
203
- end
204
- }
205
-
206
- result.promise
207
- end
150
+ def resolved?
151
+ pending.nil?
152
+ end
153
+
154
+
155
+ private
156
+
157
+
158
+ def pending
159
+ @defer.instance_eval { @pending }
160
+ end
161
+
162
+ def value
163
+ @defer.instance_eval { @value }
164
+ end
165
+ end
166
+
167
+
168
+
169
+ class ResolvedPromise < Promise
170
+ public_class_method :new
171
+
172
+ def initialize(loop, response, error = false)
173
+ raise ArgumentError if error && response.is_a?(Promise)
174
+ super()
175
+
176
+ @loop = loop
177
+ @error = error
178
+ @response = response
179
+ end
180
+
181
+ def then(callback = nil, errback = nil, progback = nil, &blk)
182
+ result = Q.defer(@loop)
183
+
184
+ callback ||= blk
185
+
186
+ @loop.next_tick {
187
+ if @error
188
+ begin
189
+ result.resolve(errback.nil? ? Q.reject(@loop, @response) : errback.call(@response))
190
+ rescue Exception => e
191
+ #warn "Unhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
192
+ result.reject(e)
193
+ @loop.log(:error, :q_reject_cb, e)
194
+ end
195
+ else
196
+ begin
197
+ result.resolve(callback.nil? ? @response : callback.call(@response))
198
+ rescue Exception => e
199
+ #warn "\nUnhandled exception: #{e.message}\n#{e.backtrace.join("\n")}\n"
200
+ result.reject(e)
201
+ @loop.log(:error, :q_resolve_cb, e)
202
+ end
203
+ end
204
+ }
205
+
206
+ result.promise
207
+ end
208
208
 
209
- def resolved?
210
- true
211
- end
212
- end
213
-
214
-
215
- #
216
- # The purpose of the deferred object is to expose the associated Promise instance as well
217
- # as APIs that can be used for signalling the successful or unsuccessful completion of a task.
218
- #
219
- class Deferred
220
- include Q
221
-
222
- def initialize(loop)
223
- super()
224
-
225
- @pending = []
226
- @value = nil
227
- @loop = loop
228
- end
229
-
230
- #
231
- # resolves the derived promise with the value. If the value is a rejection constructed via
232
- # Q.reject, the promise will be rejected instead.
233
- #
234
- # @param [Object] val constant, message or an object representing the result.
235
- def resolve(val = nil)
236
- @loop.schedule do
237
- if not @pending.nil?
238
- callbacks = @pending
239
- @pending = nil
240
- @value = ref(@loop, val)
241
-
242
- if callbacks.length > 0
243
- callbacks.each do |callback|
244
- @value.then(callback[0], callback[1], callback[2])
245
- end
246
- end
247
- end
248
- end
249
- end
250
-
251
- #
252
- # rejects the derived promise with the reason. This is equivalent to resolving it with a rejection
253
- # constructed via Q.reject.
254
- #
255
- # @param [Object] reason constant, message, exception or an object representing the rejection reason.
256
- def reject(reason = nil)
257
- resolve(Q.reject(@loop, reason))
258
- end
259
-
260
- #
261
- # Creates a promise object associated with this deferred
262
- #
263
- def promise
264
- @promise ||= DeferredPromise.new(@loop, self)
265
- @promise # Should only ever be one per deferred
266
- end
209
+ def resolved?
210
+ true
211
+ end
212
+ end
213
+
214
+
215
+ #
216
+ # The purpose of the deferred object is to expose the associated Promise instance as well
217
+ # as APIs that can be used for signalling the successful or unsuccessful completion of a task.
218
+ #
219
+ class Deferred
220
+ include Q
221
+
222
+ def initialize(loop)
223
+ super()
224
+
225
+ @pending = []
226
+ @value = nil
227
+ @loop = loop
228
+ end
229
+
230
+ #
231
+ # resolves the derived promise with the value. If the value is a rejection constructed via
232
+ # Q.reject, the promise will be rejected instead.
233
+ #
234
+ # @param [Object] val constant, message or an object representing the result.
235
+ def resolve(val = nil)
236
+ @loop.schedule do
237
+ if not @pending.nil?
238
+ callbacks = @pending
239
+ @pending = nil
240
+ @value = ref(@loop, val)
241
+
242
+ if callbacks.length > 0
243
+ callbacks.each do |callback|
244
+ @value.then(callback[0], callback[1], callback[2])
245
+ end
246
+ end
247
+ end
248
+ end
249
+ end
250
+
251
+ #
252
+ # rejects the derived promise with the reason. This is equivalent to resolving it with a rejection
253
+ # constructed via Q.reject.
254
+ #
255
+ # @param [Object] reason constant, message, exception or an object representing the rejection reason.
256
+ def reject(reason = nil)
257
+ resolve(Q.reject(@loop, reason))
258
+ end
259
+
260
+ #
261
+ # Creates a promise object associated with this deferred
262
+ #
263
+ def promise
264
+ @promise ||= DeferredPromise.new(@loop, self)
265
+ @promise # Should only ever be one per deferred
266
+ end
267
267
 
268
- #
269
- # Provides an asynchronous callback mechanism
270
- #
271
- # @param [*Object] data you would like to send down the promise chain.
272
- def notify(*args)
273
- @loop.schedule do # just in case we are on a different event loop
274
- if @pending && @pending.length > 0
275
- callbacks = @pending
276
- @loop.next_tick do
277
- callbacks.each do |callback|
278
- callback[2].call(*args)
279
- end
280
- end
281
- end
282
- end
283
- end
268
+ #
269
+ # Provides an asynchronous callback mechanism
270
+ #
271
+ # @param [*Object] data you would like to send down the promise chain.
272
+ def notify(*args)
273
+ @loop.schedule do # just in case we are on a different event loop
274
+ if @pending && @pending.length > 0
275
+ callbacks = @pending
276
+ @loop.next_tick do
277
+ callbacks.each do |callback|
278
+ callback[2].call(*args)
279
+ end
280
+ end
281
+ end
282
+ end
283
+ end
284
284
 
285
- def resolved?
286
- @pending.nil?
287
- end
288
- end
289
-
290
-
291
-
292
-
293
-
294
-
295
- #
296
- # Creates a Deferred object which represents a task which will finish in the future.
297
- #
298
- # @return [Deferred] Returns a new instance of Deferred
299
- def defer(loop)
300
- return Deferred.new(loop)
301
- end
302
-
303
-
304
- #
305
- # Creates a promise that is resolved as rejected with the specified reason. This api should be
306
- # used to forward rejection in a chain of promises. If you are dealing with the last promise in
307
- # a promise chain, you don't need to worry about it.
308
- #
309
- # When comparing deferreds/promises to the familiar behaviour of try/catch/throw, think of
310
- # reject as the raise keyword in Ruby. This also means that if you "catch" an error via
311
- # a promise error callback and you want to forward the error to the promise derived from the
312
- # current promise, you have to "rethrow" the error by returning a rejection constructed via
313
- # reject.
314
- #
315
- # @example handling rejections
316
- #
317
- # #!/usr/bin/env ruby
318
- #
319
- # require 'rubygems' # or use Bundler.setup
320
- # require 'em-promise'
321
- #
322
- # promiseB = promiseA.then(lambda {|reason|
323
- # # error: handle the error if possible and resolve promiseB with newPromiseOrValue,
324
- # # otherwise forward the rejection to promiseB
325
- # if canHandle(reason)
326
- # # handle the error and recover
327
- # return newPromiseOrValue
328
- # end
329
- # return Q.reject(loop, reason)
330
- # }, lambda {|result|
331
- # # success: do something and resolve promiseB with the old or a new result
332
- # return result
333
- # })
334
- #
335
- # @param [Object] reason constant, message, exception or an object representing the rejection reason.
336
- # @return [Promise] Returns a promise that was already resolved as rejected with the reason
337
- def reject(loop, reason = nil)
338
- return ResolvedPromise.new(loop, reason, true) # A resolved failed promise
339
- end
340
-
341
- #
342
- # Combines multiple promises into a single promise that is resolved when all of the input
343
- # promises are resolved.
344
- #
345
- # @param [*Promise] Promises a number of promises that will be combined into a single promise
346
- # @return [Promise] Returns a single promise that will be resolved with an array of values,
347
- # each value corresponding to the promise at the same index in the `promises` array. If any of
348
- # the promises is resolved with a rejection, this resulting promise will be resolved with the
349
- # same rejection.
350
- def all(loop, *promises)
351
- deferred = Q.defer(loop)
352
- counter = promises.length
353
- results = []
354
-
355
- if counter > 0
356
- promises.each_index do |index|
357
- ref(loop, promises[index]).then(proc {|result|
358
- if results[index].nil?
359
- results[index] = result
360
- counter -= 1
361
- deferred.resolve(results) if counter <= 0
362
- end
363
- result
364
- }, proc {|reason|
365
- if results[index].nil?
366
- deferred.reject(reason)
367
- end
368
- Q.reject(@loop, reason) # Don't modify result
369
- })
370
- end
371
- else
372
- deferred.resolve(results)
373
- end
374
-
375
- return deferred.promise
376
- end
285
+ def resolved?
286
+ @pending.nil?
287
+ end
377
288
 
289
+ # Overwrite to prevent inspecting errors hanging the VM
290
+ def inspect
291
+ if @pending.nil?
292
+ "#<#{self.class}:0x#{self.__id__.to_s(16)} @loop=#{@loop.inspect} @value=#{@value.inspect}>"
293
+ else
294
+ "#<#{self.class}:0x#{self.__id__.to_s(16)} @loop=#{@loop.inspect} @pending.count=#{@pending.length}>"
295
+ end
296
+ end
297
+ end
298
+
299
+
300
+
301
+
302
+
303
+
304
+ #
305
+ # Creates a Deferred object which represents a task which will finish in the future.
306
+ #
307
+ # @return [Deferred] Returns a new instance of Deferred
308
+ def defer(loop)
309
+ return Deferred.new(loop)
310
+ end
311
+
312
+
313
+ #
314
+ # Creates a promise that is resolved as rejected with the specified reason. This api should be
315
+ # used to forward rejection in a chain of promises. If you are dealing with the last promise in
316
+ # a promise chain, you don't need to worry about it.
317
+ #
318
+ # When comparing deferreds/promises to the familiar behaviour of try/catch/throw, think of
319
+ # reject as the raise keyword in Ruby. This also means that if you "catch" an error via
320
+ # a promise error callback and you want to forward the error to the promise derived from the
321
+ # current promise, you have to "rethrow" the error by returning a rejection constructed via
322
+ # reject.
323
+ #
324
+ # @example handling rejections
325
+ #
326
+ # #!/usr/bin/env ruby
327
+ #
328
+ # require 'rubygems' # or use Bundler.setup
329
+ # require 'em-promise'
330
+ #
331
+ # promiseB = promiseA.then(lambda {|reason|
332
+ # # error: handle the error if possible and resolve promiseB with newPromiseOrValue,
333
+ # # otherwise forward the rejection to promiseB
334
+ # if canHandle(reason)
335
+ # # handle the error and recover
336
+ # return newPromiseOrValue
337
+ # end
338
+ # return Q.reject(loop, reason)
339
+ # }, lambda {|result|
340
+ # # success: do something and resolve promiseB with the old or a new result
341
+ # return result
342
+ # })
343
+ #
344
+ # @param [Object] reason constant, message, exception or an object representing the rejection reason.
345
+ # @return [Promise] Returns a promise that was already resolved as rejected with the reason
346
+ def reject(loop, reason = nil)
347
+ return ResolvedPromise.new(loop, reason, true) # A resolved failed promise
348
+ end
349
+
350
+ #
351
+ # Combines multiple promises into a single promise that is resolved when all of the input
352
+ # promises are resolved.
353
+ #
354
+ # @param [*Promise] Promises a number of promises that will be combined into a single promise
355
+ # @return [Promise] Returns a single promise that will be resolved with an array of values,
356
+ # each value corresponding to the promise at the same index in the `promises` array. If any of
357
+ # the promises is resolved with a rejection, this resulting promise will be resolved with the
358
+ # same rejection.
359
+ def all(loop, *promises)
360
+ deferred = Q.defer(loop)
361
+ counter = promises.length
362
+ results = []
363
+
364
+ if counter > 0
365
+ promises.each_index do |index|
366
+ ref(loop, promises[index]).then(proc {|result|
367
+ if results[index].nil?
368
+ results[index] = result
369
+ counter -= 1
370
+ deferred.resolve(results) if counter <= 0
371
+ end
372
+ result
373
+ }, proc {|reason|
374
+ if results[index].nil?
375
+ deferred.reject(reason)
376
+ end
377
+ Q.reject(@loop, reason) # Don't modify result
378
+ })
379
+ end
380
+ else
381
+ deferred.resolve(results)
382
+ end
383
+
384
+ return deferred.promise
385
+ end
378
386
 
379
- #
380
- # Combines multiple promises into a single promise that is resolved when any of the input
381
- # promises are resolved.
382
- #
383
- # @param [*Promise] Promises a number of promises that will be combined into a single promise
384
- # @return [Promise] Returns a single promise
385
- def any(loop, *promises)
386
- deferred = Q.defer(loop)
387
- if promises.length > 0
388
- promises.each_index do |index|
389
- ref(loop, promises[index]).then(proc {|result|
390
- deferred.resolve(true)
391
- result
392
- }, proc {|reason|
393
- deferred.reject(false)
394
- Q.reject(@loop, reason) # Don't modify result
395
- })
396
- end
397
- else
398
- deferred.resolve(true)
399
- end
400
- end
401
387
 
388
+ #
389
+ # Combines multiple promises into a single promise that is resolved when any of the input
390
+ # promises are resolved.
391
+ #
392
+ # @param [*Promise] Promises a number of promises that will be combined into a single promise
393
+ # @return [Promise] Returns a single promise
394
+ def any(loop, *promises)
395
+ deferred = Q.defer(loop)
396
+ if promises.length > 0
397
+ promises.each_index do |index|
398
+ ref(loop, promises[index]).then(proc {|result|
399
+ deferred.resolve(true)
400
+ result
401
+ }, proc {|reason|
402
+ deferred.reject(false)
403
+ Q.reject(@loop, reason) # Don't modify result
404
+ })
405
+ end
406
+ else
407
+ deferred.resolve(true)
408
+ end
409
+ end
402
410
 
403
- #
404
- # Combines multiple promises into a single promise that is resolved when all of the input
405
- # promises are resolved or rejected.
406
- #
407
- # @param [*Promise] Promises a number of promises that will be combined into a single promise
408
- # @return [Promise] Returns a single promise that will be resolved with an array of values,
409
- # each [result, wasResolved] value pair corresponding to a at the same index in the `promises` array.
410
- def self.finally(loop, *promises)
411
- deferred = Q.defer(loop)
412
- counter = promises.length
413
- results = []
414
-
415
- if counter > 0
416
- promises.each_index do |index|
417
- ref(loop, promises[index]).then(proc {|result|
418
- if results[index].nil?
419
- results[index] = [result, false]
420
- counter -= 1
421
- deferred.resolve(results) if counter <= 0
422
- end
423
- result
424
- }, proc {|reason|
425
- if results[index].nil?
426
- results[index] = [reason, false]
427
- counter -= 1
428
- deferred.resolve(results) if counter <= 0
429
- end
430
- Q.reject(@loop, reason) # Don't modify result
431
- })
432
- end
433
- else
434
- deferred.resolve(results)
435
- end
436
-
437
- return deferred.promise
438
- end
439
-
440
-
441
- private
442
-
443
-
444
- def ref(loop, value)
445
- return value if value.is_a?(Promise)
446
- return ResolvedPromise.new(loop, value) # A resolved success promise
447
- end
448
-
449
-
450
- module_function :all, :reject, :defer, :ref, :any
451
- private_class_method :ref
452
- end
411
+
412
+ #
413
+ # Combines multiple promises into a single promise that is resolved when all of the input
414
+ # promises are resolved or rejected.
415
+ #
416
+ # @param [*Promise] Promises a number of promises that will be combined into a single promise
417
+ # @return [Promise] Returns a single promise that will be resolved with an array of values,
418
+ # each [result, wasResolved] value pair corresponding to a at the same index in the `promises` array.
419
+ def self.finally(loop, *promises)
420
+ deferred = Q.defer(loop)
421
+ counter = promises.length
422
+ results = []
423
+
424
+ if counter > 0
425
+ promises.each_index do |index|
426
+ ref(loop, promises[index]).then(proc {|result|
427
+ if results[index].nil?
428
+ results[index] = [result, false]
429
+ counter -= 1
430
+ deferred.resolve(results) if counter <= 0
431
+ end
432
+ result
433
+ }, proc {|reason|
434
+ if results[index].nil?
435
+ results[index] = [reason, false]
436
+ counter -= 1
437
+ deferred.resolve(results) if counter <= 0
438
+ end
439
+ Q.reject(@loop, reason) # Don't modify result
440
+ })
441
+ end
442
+ else
443
+ deferred.resolve(results)
444
+ end
445
+
446
+ return deferred.promise
447
+ end
448
+
449
+
450
+ private
451
+
452
+
453
+ def ref(loop, value)
454
+ return value if value.is_a?(Promise)
455
+ return ResolvedPromise.new(loop, value) # A resolved success promise
456
+ end
457
+
458
+
459
+ module_function :all, :reject, :defer, :ref, :any
460
+ private_class_method :ref
461
+ end
453
462
 
454
463
  end
data/lib/libuv/timer.rb CHANGED
@@ -68,17 +68,11 @@ module Libuv
68
68
  private
69
69
 
70
70
 
71
- def on_timer(handle, status)
72
- e = check_result(status)
73
-
74
- if e
75
- reject(e)
76
- else
77
- begin
78
- @callback.call
79
- rescue Exception => e
80
- @loop.log :error, :timer_cb, e
81
- end
71
+ def on_timer(handle)
72
+ begin
73
+ @callback.call
74
+ rescue Exception => e
75
+ @loop.log :error, :timer_cb, e
82
76
  end
83
77
  end
84
78
  end
data/lib/libuv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Libuv
2
- VERSION = '0.12.2'
2
+ VERSION = '0.12.3'
3
3
  end
data/spec/tcp_spec.rb CHANGED
@@ -35,9 +35,9 @@ describe Libuv::TCP do
35
35
  @loop.run { |logger|
36
36
  logger.progress do |level, errorid, error|
37
37
  begin
38
- @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
39
- rescue Exception
40
- @general_failure << 'error in logger'
38
+ @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n") if error.backtrace}\n"
39
+ rescue Exception => e
40
+ @general_failure << "error in logger #{e.inspect}"
41
41
  end
42
42
  end
43
43
 
@@ -98,9 +98,9 @@ describe Libuv::TCP do
98
98
  @loop.run { |logger|
99
99
  logger.progress do |level, errorid, error|
100
100
  begin
101
- @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
101
+ @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n") if error.backtrace}\n"
102
102
  rescue Exception
103
- @general_failure << 'error in logger'
103
+ @general_failure << "error in logger #{e.inspect}"
104
104
  end
105
105
  end
106
106
 
@@ -169,9 +169,9 @@ describe Libuv::TCP do
169
169
  @loop2.run do |logger|
170
170
  logger.progress do |level, errorid, error|
171
171
  begin
172
- @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
172
+ @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n") if error.backtrace}\n"
173
173
  rescue Exception
174
- @general_failure << 'error in logger'
174
+ @general_failure << "error in logger #{e.inspect}"
175
175
  end
176
176
  end
177
177
 
@@ -209,9 +209,9 @@ describe Libuv::TCP do
209
209
  @loop.run { |logger|
210
210
  logger.progress do |level, errorid, error|
211
211
  begin
212
- @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
212
+ @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n") if error.backtrace}\n"
213
213
  rescue Exception
214
- @general_failure << 'error in logger'
214
+ @general_failure << "error in logger #{e.inspect}"
215
215
  end
216
216
  end
217
217
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libuv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bulat Shakirzyanov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-01 00:00:00.000000000 Z
12
+ date: 2014-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -175,6 +175,7 @@ files:
175
175
  - ext/libuv/common.gypi
176
176
  - ext/libuv/configure.ac
177
177
  - ext/libuv/gyp_uv.py
178
+ - ext/libuv/include/android-ifaddrs.h
178
179
  - ext/libuv/include/pthread-fixes.h
179
180
  - ext/libuv/include/stdint-msvc2008.h
180
181
  - ext/libuv/include/tree.h
@@ -189,6 +190,7 @@ files:
189
190
  - ext/libuv/include/uv.h
190
191
  - ext/libuv/libuv.pc.in
191
192
  - ext/libuv/m4/.gitignore
193
+ - ext/libuv/m4/as_case.m4
192
194
  - ext/libuv/m4/dtrace.m4
193
195
  - ext/libuv/samples/.gitignore
194
196
  - ext/libuv/samples/socks5-proxy/.gitignore
@@ -208,6 +210,7 @@ files:
208
210
  - ext/libuv/src/inet.c
209
211
  - ext/libuv/src/queue.h
210
212
  - ext/libuv/src/unix/aix.c
213
+ - ext/libuv/src/unix/android-ifaddrs.c
211
214
  - ext/libuv/src/unix/async.c
212
215
  - ext/libuv/src/unix/atomic-ops.h
213
216
  - ext/libuv/src/unix/core.c
@@ -396,10 +399,13 @@ files:
396
399
  - ext/libuv/test/test-timer-from-check.c
397
400
  - ext/libuv/test/test-timer.c
398
401
  - ext/libuv/test/test-tty.c
402
+ - ext/libuv/test/test-udp-bind.c
399
403
  - ext/libuv/test/test-udp-dgram-too-big.c
400
404
  - ext/libuv/test/test-udp-ipv6.c
401
405
  - ext/libuv/test/test-udp-multicast-interface.c
406
+ - ext/libuv/test/test-udp-multicast-interface6.c
402
407
  - ext/libuv/test/test-udp-multicast-join.c
408
+ - ext/libuv/test/test-udp-multicast-join6.c
403
409
  - ext/libuv/test/test-udp-multicast-ttl.c
404
410
  - ext/libuv/test/test-udp-open.c
405
411
  - ext/libuv/test/test-udp-options.c
@@ -428,7 +434,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
428
434
  version: '0'
429
435
  requirements: []
430
436
  rubyforge_project:
431
- rubygems_version: 2.1.11
437
+ rubygems_version: 2.0.3
432
438
  signing_key:
433
439
  specification_version: 4
434
440
  summary: libuv bindings for Ruby