timers 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ 1.1.0
2
+ -----
3
+ * Timers#after_milliseconds and #after_ms for waiting in milliseconds
4
+
1
5
  1.0.2
2
6
  -----
3
7
  * Handle overdue timers correctly
@@ -16,6 +16,16 @@ class Timers
16
16
  def after(interval, &block)
17
17
  Timer.new(self, interval, false, &block)
18
18
  end
19
+
20
+ # Call the given block after the given interval has expired. +interval+
21
+ # is measured in milliseconds.
22
+ #
23
+ # Timer.new.after_milliseconds(25) { puts "fired!" }
24
+ #
25
+ def after_milliseconds(interval, &block)
26
+ after(interval / 1000.0, &block)
27
+ end
28
+ alias_method :after_ms, :after_milliseconds
19
29
 
20
30
  # Call the given block periodically at the given interval
21
31
  def every(interval, &block)
@@ -1,3 +1,3 @@
1
1
  class Timers
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Timers do
4
- # Level of accuracy enforced by the tests (50ms)
4
+ # Level of accuracy enforced by most tests (50ms)
5
5
  Q = 0.05
6
6
 
7
7
  it "sleeps until the next timer" do
@@ -63,4 +63,15 @@ describe Timers do
63
63
  result.should == [:foo, :foo]
64
64
  end
65
65
  end
66
+
67
+ describe "millisecond timers" do
68
+ it "calculates the proper interval to wait until firing" do
69
+ interval_ms = 25
70
+
71
+ subject.after_milliseconds(interval_ms)
72
+ expected_elapse = subject.wait_interval
73
+
74
+ subject.wait_interval.should be_within(Q).of (interval_ms / 1000.0)
75
+ end
76
+ end
66
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-12 00:00:00.000000000 Z
12
+ date: 2013-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -75,15 +75,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 1264960547307952819
78
81
  required_rubygems_version: !ruby/object:Gem::Requirement
79
82
  none: false
80
83
  requirements:
81
84
  - - ! '>='
82
85
  - !ruby/object:Gem::Version
83
86
  version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 1264960547307952819
84
90
  requirements: []
85
91
  rubyforge_project:
86
- rubygems_version: 1.8.24
92
+ rubygems_version: 1.8.23
87
93
  signing_key:
88
94
  specification_version: 3
89
95
  summary: Schedule procs to run after a certain time, or at periodic intervals, using