atdo 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -1
- data/lib/atdo.rb +15 -6
- data/test/test-atdo.rb +26 -2
- 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: 766d057a668bcb0efce00c55758f212ef8a2cced
|
4
|
+
data.tar.gz: 99b9259e58f6a311d695545f7fe5bb58e8844849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/atdo.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'thread'
|
2
2
|
|
3
3
|
class AtDo
|
4
|
-
VERSION = "0.
|
4
|
+
VERSION = "0.4"
|
5
5
|
|
6
|
-
|
7
|
-
|
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
|
-
@
|
27
|
-
|
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
|
data/test/test-atdo.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'atdo'
|
3
3
|
|
4
|
-
|
4
|
+
module AtDoTests
|
5
5
|
def setup
|
6
|
-
@s =
|
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.
|
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-
|
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
|