atdo 0.3 → 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -1
  3. data/lib/atdo.rb +15 -6
  4. data/test/test-atdo.rb +26 -2
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: deedb56fa531c6a41a0c0d7536e9eedcc32b0155
4
- data.tar.gz: d1a079aa08f9d0a23a0585fc0299a4a70892d7f2
3
+ metadata.gz: 766d057a668bcb0efce00c55758f212ef8a2cced
4
+ data.tar.gz: 99b9259e58f6a311d695545f7fe5bb58e8844849
5
5
  SHA512:
6
- metadata.gz: 13f6bead5151b902888637b2374542dfc3a50c32b56be504e231e5fad94e2cb51fd7942dea830e8af1bd6f92a77d7cdee5f3ba8a611287b5c6bfef16d5cf6c0c
7
- data.tar.gz: dfa6afd17bd3dcce51c6e993be0a61232d3576ad7838cb79cc4643243986c5e70f863508464acaeb454c9cffd6ae959a7b901afc5b9187381ba37015f9633da5
6
+ metadata.gz: 16b0f91c852c9e84072d3e5ab9b644f646f8e3c7af792e21d6a836ae0292763d7103bda5442e3acbdc5e5448efdbc66d392c98beca9854a35ca52227fd459dfa
7
+ data.tar.gz: 4e10c64a187a7e0f361e17ec5f13fdd2441c2ca4259fab0c076c48f76059e001fa4ab1b2dcbfb7782aca198297775b64f017bb7860df42b8eea7b7f9cbe52894
data/Rakefile CHANGED
@@ -53,10 +53,16 @@ end
53
53
  namespace :release do
54
54
  desc "Diff to latest release"
55
55
  task :diff do
56
- latest = `git describe --abbrev=0 --tags`
56
+ latest = `git describe --abbrev=0 --tags --match '#{PRJ}-*'`.chomp
57
57
  sh "git diff #{latest}"
58
58
  end
59
59
 
60
+ desc "Log to latest release"
61
+ task :log do
62
+ latest = `git describe --abbrev=0 --tags --match '#{PRJ}-*'`.chomp
63
+ sh "git log #{latest}.."
64
+ end
65
+
60
66
  task :is_new_version do
61
67
  abort "#{tag} exists; update version!" unless `git tag -l #{tag}`.empty?
62
68
  end
@@ -1,10 +1,13 @@
1
1
  require 'thread'
2
2
 
3
3
  class AtDo
4
- VERSION = "0.3"
4
+ VERSION = "0.4"
5
5
 
6
- def initialize
7
- @events = [] ## option to use rbtree
6
+ # Storage classes known to work: Array (default), MultiRBTree.
7
+ def initialize storage: Array
8
+ @storage_class = storage
9
+ @events = storage.new
10
+ @sorted = !defined?(@events.reverse)
8
11
  @mon = Monitor.new
9
12
  @cvar = @mon.new_cond
10
13
  @thread = nil
@@ -23,10 +26,16 @@ class AtDo
23
26
  def at time, &action
24
27
  thread
25
28
  @mon.synchronize do
26
- @events << [time, action]
27
- t, a = @events.sort_by! {|t, a| t}.first
29
+ if @sorted
30
+ @events[time] = action
31
+ t, _ = @events.first
32
+ else
33
+ @events << [time, action]
34
+ t, _ = @events.sort_by! {|t, a| t}.first
35
+ end
28
36
  @cvar.signal if t == time
29
37
  end
38
+ self
30
39
  end
31
40
 
32
41
  def thread
@@ -42,7 +51,7 @@ class AtDo
42
51
  begin
43
52
  a.call
44
53
  rescue => ex
45
- ## ?
54
+ # exception handling is left to client code
46
55
  end
47
56
  @events.shift
48
57
  end
@@ -1,9 +1,9 @@
1
1
  require 'minitest/autorun'
2
2
  require 'atdo'
3
3
 
4
- class TestAtDo < Minitest::Test
4
+ module AtDoTests
5
5
  def setup
6
- @s = AtDo.new
6
+ @s = make_atdo
7
7
  end
8
8
 
9
9
  def teardown
@@ -77,3 +77,27 @@ class TestAtDo < Minitest::Test
77
77
  assert_equal "sleep", @s.thread.status
78
78
  end
79
79
  end
80
+
81
+ class TestAtDo < Minitest::Test
82
+ include AtDoTests
83
+
84
+ def make_atdo
85
+ AtDo.new
86
+ end
87
+ end
88
+
89
+ begin
90
+ require 'rbtree'
91
+
92
+ rescue LoadError => ex
93
+ $stderr.puts "skipping tests for AtDo with RBTree: #{ex}"
94
+
95
+ else
96
+ class TestAtDoRBTree < Minitest::Test
97
+ include AtDoTests
98
+
99
+ def make_atdo
100
+ AtDo.new storage: MultiRBTree
101
+ end
102
+ end
103
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atdo
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel VanderWerf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-21 00:00:00.000000000 Z
11
+ date: 2013-09-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: At time, do code.
14
14
  email: vjoel@users.sourceforge.net