zoidberg 0.1.0 → 0.1.2
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 +12 -23
- 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: 231615060c80d5ca9662a95eb70688e1b11208e9
|
4
|
+
data.tar.gz: 83b5a508225ce56f2dbe124a54b77941b99677fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b50938806d8da937ff0778a1772a2fe458503c34936295c5ed87a16cdee2ab101b00bef94c29eb046ffd4022de077647bd4568ec5d9ded5e3c476f18e27a4b6
|
7
|
+
data.tar.gz: 9188f12d3184e78ba89c84a93e72d6540ac4e9d801fd411e3df383d74a1d15edf454ca2de2f57a3f2d7e9b2f196f777ce4e0608199dcd7e938fce90acc871852
|
data/CHANGELOG.md
CHANGED
data/lib/zoidberg/timer.rb
CHANGED
@@ -15,6 +15,8 @@ module Zoidberg
|
|
15
15
|
attr_reader :interval
|
16
16
|
# @return [Float]
|
17
17
|
attr_reader :last_run
|
18
|
+
# @return [IO]
|
19
|
+
attr_reader :waker
|
18
20
|
|
19
21
|
# Create a new action
|
20
22
|
#
|
@@ -31,6 +33,7 @@ module Zoidberg
|
|
31
33
|
@interval = args.fetch(:interval, 5)
|
32
34
|
@last_run = Time.now.to_f
|
33
35
|
@cancel = false
|
36
|
+
@waker = IO.pipe.last
|
34
37
|
end
|
35
38
|
|
36
39
|
# Cancel the action
|
@@ -63,8 +66,6 @@ module Zoidberg
|
|
63
66
|
# Custom exception used to wakeup timer
|
64
67
|
class Wakeup < StandardError; end
|
65
68
|
|
66
|
-
# @return [Mutex]
|
67
|
-
attr_reader :notify_locker
|
68
69
|
# @return [Array<Action>] items to run
|
69
70
|
attr_reader :to_run
|
70
71
|
# @return [TrueClass, FalseClass] timer is paused
|
@@ -75,7 +76,6 @@ module Zoidberg
|
|
75
76
|
# @return [self]
|
76
77
|
def initialize
|
77
78
|
@to_run = []
|
78
|
-
@notify_locker = Mutex.new
|
79
79
|
@paused = false
|
80
80
|
@thread = Thread.new{ run! }
|
81
81
|
end
|
@@ -148,17 +148,11 @@ module Zoidberg
|
|
148
148
|
# @param wakeup [TrueClass, FalseClass] wakeup the timer thread
|
149
149
|
# @return [self]
|
150
150
|
def reset(wakeup=true)
|
151
|
+
to_run.sort_by! do |item|
|
152
|
+
(item.interval + item.last_run) - Time.now.to_f
|
153
|
+
end
|
151
154
|
if(wakeup)
|
152
|
-
|
153
|
-
to_run.sort_by! do |item|
|
154
|
-
(item.interval + item.last_run) - Time.now.to_f
|
155
|
-
end
|
156
|
-
@thread.raise Wakeup.new
|
157
|
-
end
|
158
|
-
else
|
159
|
-
to_run.sort_by! do |item|
|
160
|
-
(item.interval + item.last_run) - Time.now.to_f
|
161
|
-
end
|
155
|
+
waker.write '-'
|
162
156
|
end
|
163
157
|
current_self
|
164
158
|
end
|
@@ -203,16 +197,11 @@ module Zoidberg
|
|
203
197
|
def run!
|
204
198
|
loop do
|
205
199
|
begin
|
206
|
-
interval =
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
sleep interval
|
212
|
-
notify_locker.synchronize do
|
213
|
-
run_ready
|
214
|
-
reset(false)
|
215
|
-
end
|
200
|
+
interval = current_self.next_interval
|
201
|
+
io = IO.select([waker], [], [], interval).flatten.compact.first
|
202
|
+
io.read if io
|
203
|
+
current_self.run_ready
|
204
|
+
current_self.reset(false)
|
216
205
|
rescue Wakeup
|
217
206
|
Zoidberg.logger.debug "<#{self}> Received wakeup notification. Rechecking sleep interval!"
|
218
207
|
rescue DeadException
|
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.2
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogo
|