wdd-ruby-ext 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/wdd-ruby-ext/utils/time_gate.rb +22 -6
- data/wdd-ruby-ext.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
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.
|
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.
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- shock
|