wdd-ruby-ext 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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -16,12 +16,12 @@ module WDD
16
16
  # +block+ - true by default. If false, the method will not block, but will return the amount of time
17
17
  # left before the gate opens.
18
18
  # An optional Ruby block can be passed when +block+ is true that will be evaluated
19
- # every 0.2 seconds. If the block evaluates to false, the latch is released and this method returns.
19
+ # every 0.5 seconds. If the block evaluates to false, the latch is released and this method returns.
20
20
  def wait block = true
21
21
  if block
22
22
  guard = block_given? ? yield : true
23
23
  while Time.now < @gate_time && guard do
24
- sleep 0.2
24
+ sleep 0.5
25
25
  end
26
26
  else
27
27
  Time.now < @gate_time
@@ -33,10 +33,26 @@ module WDD
33
33
  end
34
34
  end
35
35
 
36
- def self.elapsed_time &block
37
- start_time = Time.now
38
- yield
39
- Time.now - start_time
36
+ class << self
37
+ # Evaluated the passed block and returns the elapsed wall clock time.
38
+ def elapsed_time &block
39
+ start_time = Time.now
40
+ yield
41
+ Time.now - start_time
42
+ end
43
+
44
+ # Sleeps the specified interval. If a block is passed, it will be evaluated every +guard_interval+ seconds.
45
+ # If it evaluates to true, the sleep will be interrupted and control will be returned to the caller.
46
+ def interruptable_sleep sleep_time, guard_interval=0.5
47
+ if block_given?
48
+ while( yield && sleep_time > 0 )
49
+ sleep guard_interval
50
+ sleep_time -= guard_interval
51
+ end
52
+ else
53
+ sleep sleep_time
54
+ end
55
+ end
40
56
  end
41
57
  end
42
58
  end
data/wdd-ruby-ext.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wdd-ruby-ext}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["shock"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wdd-ruby-ext
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - shock