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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 231615060c80d5ca9662a95eb70688e1b11208e9
4
- data.tar.gz: 83b5a508225ce56f2dbe124a54b77941b99677fd
3
+ metadata.gz: 3632fd491e21d5b71dca06d2670227b281b27865
4
+ data.tar.gz: 360be229f5e280316a28b6505b80e08fba50220b
5
5
  SHA512:
6
- metadata.gz: 8b50938806d8da937ff0778a1772a2fe458503c34936295c5ed87a16cdee2ab101b00bef94c29eb046ffd4022de077647bd4568ec5d9ded5e3c476f18e27a4b6
7
- data.tar.gz: 9188f12d3184e78ba89c84a93e72d6540ac4e9d801fd411e3df383d74a1d15edf454ca2de2f57a3f2d7e9b2f196f777ce4e0608199dcd7e938fce90acc871852
6
+ metadata.gz: f3d3c32e84acbd7b470f16166b070b8bf219d3db1d548eeb25bb758e9675c1b8b864ec45cbe5b4536b402147ce6b0513cefbb5af2008855eea4af48a21c29366
7
+ data.tar.gz: 3bd1a5562bdab8f04ac8f0e1381b1db7aa10c33cb0e1f83e334802cf348b329dae5e6091052b875efab3b3c740371620147c679dcbdb72962f5cb690321fa15c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.1.4
2
+ * Timer updates and fix spec
3
+
1
4
  # v0.1.2
2
5
  * Use select + pipe for timer interactions
3
6
 
@@ -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 do |item|
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
- 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)
205
- rescue Wakeup
206
- Zoidberg.logger.debug "<#{self}> Received wakeup notification. Rechecking sleep interval!"
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
@@ -1,4 +1,4 @@
1
1
  module Zoidberg
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.2')
3
+ VERSION = Gem::Version.new('0.1.4')
4
4
  end
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.2
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-16 00:00:00.000000000 Z
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo