ione 1.1.3.pre0 → 1.1.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: 683f88dbcc94dbca64fc620cbad845bfb7eb359e
4
- data.tar.gz: eda5367f48dda6be7a53664dc219b39e71797634
3
+ metadata.gz: 7d699b8de5df4bf4aa1f1033562686f1ee419bca
4
+ data.tar.gz: 550b2de454ca6a4971690b75d7cd6a8c6e0f460d
5
5
  SHA512:
6
- metadata.gz: bdadd53947a7b24140b2d2a2dba5615a4251576af3114e6da458ec9c4d47b0be578d93d1f13f2bff774d49fbb85668430312d4fd4c0e4a211969b82ca24c38c9
7
- data.tar.gz: d4d1dd59ae9d4300483c0b9e65084d905f80911d126ba1984f89537e4f53e2bfc7468c6bd7c45dc7fb4ef9c564046e654103e09367ce9349a5156835361deb19
6
+ metadata.gz: 007316cffbaeb575aad0ee56c17dec8ac5caf817df6b875e8747eacae4063d2d4c67424271ab0c4916a6d23badd4e338fe8bd12574189510a79f2214d07c186c
7
+ data.tar.gz: a11900b252d0c3ee6a5d24aeff26a6206dd0d04604b49740192549fb6b5bfde5ce79bd76ea8297be5b0c0a34e45c60ce9b03d03260e8d526707fef90735cca2a
@@ -195,6 +195,15 @@ module Ione
195
195
  @io_loop.schedule_timer(timeout)
196
196
  end
197
197
 
198
+ # Cancels a previously scheduled timer.
199
+ #
200
+ # The timer will fail with a {Ione::CancelledError}.
201
+ #
202
+ # @param timer_future [Ione::Future] the future returned by {#schedule_timer}
203
+ def cancel_timer(timer_future)
204
+ @io_loop.cancel_timer(timer_future)
205
+ end
206
+
198
207
  def to_s
199
208
  @io_loop.to_s
200
209
  end
@@ -283,6 +292,16 @@ module Ione
283
292
  @lock.unlock
284
293
  end
285
294
 
295
+ def cancel_timer(timer_future)
296
+ @lock.lock
297
+ timer_pair = @timers.find { |pair| (p = pair[1]) && p.future == timer_future }
298
+ @timers = @timers.reject { |pair| pair[1].nil? || pair == timer_pair }
299
+ timer_pair && timer_pair[1].fail(CancelledError.new)
300
+ nil
301
+ ensure
302
+ @lock.unlock
303
+ end
304
+
286
305
  def close_sockets
287
306
  @sockets.each do |s|
288
307
  begin
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Ione
4
- VERSION = '1.1.3.pre0'.freeze
4
+ VERSION = '1.1.3'.freeze
5
5
  end
@@ -223,6 +223,59 @@ module Ione
223
223
  end
224
224
  end
225
225
 
226
+ describe '#cancel_timer' do
227
+ before do
228
+ reactor.start.value
229
+ end
230
+
231
+ after do
232
+ reactor.stop.value
233
+ end
234
+
235
+ it 'fails the timer future' do
236
+ clock.stub(:now).and_return(1)
237
+ f = reactor.schedule_timer(0.1)
238
+ reactor.cancel_timer(f)
239
+ await { f.failed? }
240
+ end
241
+
242
+ it 'does not trigger the timer future when it expires' do
243
+ clock.stub(:now).and_return(1)
244
+ f = reactor.schedule_timer(0.1)
245
+ reactor.cancel_timer(f)
246
+ clock.stub(:now).and_return(1.1)
247
+ await { f.failed? }
248
+ end
249
+
250
+ it 'fails the future with a CancelledError' do
251
+ clock.stub(:now).and_return(1)
252
+ f = reactor.schedule_timer(0.1)
253
+ reactor.cancel_timer(f)
254
+ await { f.failed? }
255
+ expect { f.value }.to raise_error(CancelledError)
256
+ end
257
+
258
+ it 'does nothing when the timer has already expired' do
259
+ clock.stub(:now).and_return(1)
260
+ f = reactor.schedule_timer(0.1)
261
+ clock.stub(:now).and_return(1.1)
262
+ await { f.resolved? }
263
+ reactor.cancel_timer(f)
264
+ end
265
+
266
+ it 'does nothing when given a future that is not a timer' do
267
+ reactor.cancel_timer(Ione::Promise.new.future)
268
+ end
269
+
270
+ it 'does nothing when given something that is not a future' do
271
+ reactor.cancel_timer(:foobar)
272
+ end
273
+
274
+ it 'does nothing when given nil' do
275
+ reactor.cancel_timer(nil)
276
+ end
277
+ end
278
+
226
279
  describe '#to_s' do
227
280
  context 'returns a string that' do
228
281
  it 'includes the class name' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ione
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3.pre0
4
+ version: 1.1.3
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-06-11 00:00:00.000000000 Z
11
+ date: 2014-06-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Reactive programming framework for Ruby, painless evented IO, futures
14
14
  and an efficient byte buffer
@@ -56,9 +56,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
56
  version: 1.9.3
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>'
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.1
61
+ version: '0'
62
62
  requirements: []
63
63
  rubyforge_project:
64
64
  rubygems_version: 2.2.1