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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f12f7686bfce42183b33d6a765027eed64113aee
4
- data.tar.gz: 1b12f2ad1e6210a086c60c3dac02599cef678ba1
3
+ metadata.gz: 231615060c80d5ca9662a95eb70688e1b11208e9
4
+ data.tar.gz: 83b5a508225ce56f2dbe124a54b77941b99677fd
5
5
  SHA512:
6
- metadata.gz: 17f6a8e0cb57573076bbeb852c392699b8bdbde0f88b9818a213704cfb6e1c5c37e80cd6b207821e61f47f4d30e8825177e671136e209e2e197e1f0735063dd9
7
- data.tar.gz: f8d4c6aba250fdf670e996bbb8668081cb21aa2ab0c8a049c7c8878f086af766e4525de47e2e1968c0b431985bdf3894ac05627a485b21fe78dbddb70dc048c9
6
+ metadata.gz: 8b50938806d8da937ff0778a1772a2fe458503c34936295c5ed87a16cdee2ab101b00bef94c29eb046ffd4022de077647bd4568ec5d9ded5e3c476f18e27a4b6
7
+ data.tar.gz: 9188f12d3184e78ba89c84a93e72d6540ac4e9d801fd411e3df383d74a1d15edf454ca2de2f57a3f2d7e9b2f196f777ce4e0608199dcd7e938fce90acc871852
data/CHANGELOG.md CHANGED
@@ -1,2 +1,5 @@
1
+ # v0.1.2
2
+ * Use select + pipe for timer interactions
3
+
1
4
  # v0.1.0
2
5
  * Initial release
@@ -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
- notify_locker.synchronize do
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 = nil
207
- # TODO: update with select for better subsecond support
208
- notify_locker.synchronize do
209
- interval = next_interval
210
- end
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
@@ -1,4 +1,4 @@
1
1
  module Zoidberg
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.0')
3
+ VERSION = Gem::Version.new('0.1.2')
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.0
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 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo