zoidberg 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/zoidberg/timer.rb +27 -14
- data/lib/zoidberg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3632fd491e21d5b71dca06d2670227b281b27865
|
4
|
+
data.tar.gz: 360be229f5e280316a28b6505b80e08fba50220b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3d3c32e84acbd7b470f16166b070b8bf219d3db1d548eeb25bb758e9675c1b8b864ec45cbe5b4536b402147ce6b0513cefbb5af2008855eea4af48a21c29366
|
7
|
+
data.tar.gz: 3bd1a5562bdab8f04ac8f0e1381b1db7aa10c33cb0e1f83e334802cf348b329dae5e6091052b875efab3b3c740371620147c679dcbdb72962f5cb690321fa15c
|
data/CHANGELOG.md
CHANGED
data/lib/zoidberg/timer.rb
CHANGED
@@ -15,8 +15,6 @@ module Zoidberg
|
|
15
15
|
attr_reader :interval
|
16
16
|
# @return [Float]
|
17
17
|
attr_reader :last_run
|
18
|
-
# @return [IO]
|
19
|
-
attr_reader :waker
|
20
18
|
|
21
19
|
# Create a new action
|
22
20
|
#
|
@@ -33,7 +31,6 @@ module Zoidberg
|
|
33
31
|
@interval = args.fetch(:interval, 5)
|
34
32
|
@last_run = Time.now.to_f
|
35
33
|
@cancel = false
|
36
|
-
@waker = IO.pipe.last
|
37
34
|
end
|
38
35
|
|
39
36
|
# Cancel the action
|
@@ -59,6 +56,15 @@ module Zoidberg
|
|
59
56
|
self
|
60
57
|
end
|
61
58
|
|
59
|
+
# @return [TrueClass, FalseClass]
|
60
|
+
def ready?
|
61
|
+
!cancelled? && (
|
62
|
+
Time.now.to_f > (
|
63
|
+
last_run + interval
|
64
|
+
)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
62
68
|
end
|
63
69
|
|
64
70
|
include Zoidberg::SoftShell
|
@@ -66,10 +72,17 @@ module Zoidberg
|
|
66
72
|
# Custom exception used to wakeup timer
|
67
73
|
class Wakeup < StandardError; end
|
68
74
|
|
75
|
+
# Wakeup string
|
76
|
+
WAKEUP = "WAKEUP\n"
|
77
|
+
|
69
78
|
# @return [Array<Action>] items to run
|
70
79
|
attr_reader :to_run
|
71
80
|
# @return [TrueClass, FalseClass] timer is paused
|
72
81
|
attr_reader :paused
|
82
|
+
# @return [IO]
|
83
|
+
attr_reader :waker
|
84
|
+
# @return [IO]
|
85
|
+
attr_reader :alerter
|
73
86
|
|
74
87
|
# Create a new timer
|
75
88
|
#
|
@@ -77,6 +90,7 @@ module Zoidberg
|
|
77
90
|
def initialize
|
78
91
|
@to_run = []
|
79
92
|
@paused = false
|
93
|
+
@alerter, @waker = IO.pipe
|
80
94
|
@thread = Thread.new{ run! }
|
81
95
|
end
|
82
96
|
|
@@ -152,7 +166,7 @@ module Zoidberg
|
|
152
166
|
(item.interval + item.last_run) - Time.now.to_f
|
153
167
|
end
|
154
168
|
if(wakeup)
|
155
|
-
waker.write
|
169
|
+
waker.write WAKEUP
|
156
170
|
end
|
157
171
|
current_self
|
158
172
|
end
|
@@ -170,9 +184,7 @@ module Zoidberg
|
|
170
184
|
#
|
171
185
|
# @return [self]
|
172
186
|
def run_ready
|
173
|
-
items = to_run.find_all
|
174
|
-
((item.interval + item.last_run) - Time.now.to_f) <= 0
|
175
|
-
end
|
187
|
+
items = to_run.find_all(&:ready?)
|
176
188
|
to_run.delete_if do |item|
|
177
189
|
items.include?(item)
|
178
190
|
end
|
@@ -197,13 +209,14 @@ module Zoidberg
|
|
197
209
|
def run!
|
198
210
|
loop do
|
199
211
|
begin
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
212
|
+
alerter.read_nonblock(WAKEUP.length)
|
213
|
+
rescue IO::WaitReadable
|
214
|
+
interval = current_self.next_interval if current_self
|
215
|
+
IO.select([alerter], [], [], interval)
|
216
|
+
end
|
217
|
+
begin
|
218
|
+
run_ready
|
219
|
+
reset(false)
|
207
220
|
rescue DeadException
|
208
221
|
raise
|
209
222
|
rescue => e
|
data/lib/zoidberg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoidberg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogo
|