atdo 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +1 -1
  3. data/Rakefile +2 -2
  4. data/lib/atdo.rb +16 -12
  5. data/test/test-atdo.rb +1 -1
  6. metadata +12 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce5b3c549e91ce0834c69acc4becba2b11e5bb98
4
- data.tar.gz: 78eba666d55525e0f22f7932f618f4cf1dbad4c6
3
+ metadata.gz: 1bc614d7dbd02c65ec1ee0d06a7e951b079a5580
4
+ data.tar.gz: d2f809e142ba2da4d074379a899a5a94e9368cbf
5
5
  SHA512:
6
- metadata.gz: 8ec3c9c9c67d364f9f1b054357a21c33bd8171ef862b33ef6dcfe9f0759e719ec77646d63cba853508da2cacfb18e0a85b0ead6aa05c227339148792a4a2c4be
7
- data.tar.gz: 5e8b2d638380995afee556a3aa4459c89791bf2f66bebdd648c86d9524f1371de01f7c2aa32f9c666fe084f414f9663243c7a6ee01ca65e99ff4533c25f96166
6
+ metadata.gz: 0fd2a362804997809a2aa32ecc2a91a949fbabaf372a4a95a9f601d2e3ec4775823bbd371f9d75d4584176b51e3b8d43ae7a5ab4cff6980faa91fbafab190ff4
7
+ data.tar.gz: 55b7218d746e7c530bda0ece279866d4be763c1ad4af69ab729695de276eaa6dd7ab8e94eeb0060c5ff46cc21e2fd19066be1a4bbfc3656357b23e9baee064a2
data/COPYING CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013, Joel VanderWerf, vjoel@users.sourceforge.net
1
+ Copyright (c) 2013-2014, Joel VanderWerf, vjoel@users.sourceforge.net
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/Rakefile CHANGED
@@ -30,7 +30,7 @@ end
30
30
  desc "Commit, tag, and push repo; build and push gem"
31
31
  task :release => "release:is_new_version" do
32
32
  require 'tempfile'
33
-
33
+
34
34
  sh "gem build #{PRJ}.gemspec"
35
35
 
36
36
  file = Tempfile.new "template"
@@ -46,7 +46,7 @@ task :release => "release:is_new_version" do
46
46
  sh "git tag #{tag}"
47
47
  sh "git push"
48
48
  sh "git push --tags"
49
-
49
+
50
50
  sh "gem push #{tag}.gem"
51
51
  end
52
52
 
@@ -1,7 +1,7 @@
1
1
  require 'thread'
2
2
 
3
3
  class AtDo
4
- VERSION = "0.5"
4
+ VERSION = "0.6"
5
5
 
6
6
  # Storage classes known to work: Array (default), MultiRBTree.
7
7
  def initialize storage: Array
@@ -11,9 +11,12 @@ class AtDo
11
11
  @mon = Monitor.new
12
12
  @cvar = @mon.new_cond
13
13
  @thread = nil
14
- @t0 = Time.now
15
14
  end
16
-
15
+
16
+ def inspect
17
+ "#<#{self.class}:0x#{self.object_id.to_s(16)} #{@events}>"
18
+ end
19
+
17
20
  def stop
18
21
  @mon.synchronize do
19
22
  @thread.kill if @thread
@@ -23,27 +26,28 @@ class AtDo
23
26
  def stop!
24
27
  @thread.kill if @thread
25
28
  end
26
-
29
+
27
30
  def wait
28
31
  @thread.join
29
32
  end
30
-
33
+
31
34
  def at time, &action
32
35
  thread
33
- time < @t0
36
+ raise ArgumentError unless time.kind_of? Time
37
+
34
38
  @mon.synchronize do
35
39
  if @sorted
36
40
  @events[time] = action
37
- t, _ = @events.first
41
+ first_event_time, _ = @events.first
38
42
  else
39
43
  @events << [time, action]
40
- t, _ = @events.sort_by! {|t, a| t}.first
44
+ first_event_time, _ = @events.sort_by! {|t, a| t}.first
41
45
  end
42
- @cvar.signal if t == time
46
+ @cvar.signal if first_event_time == time
43
47
  end
44
48
  self
45
49
  end
46
-
50
+
47
51
  def thread
48
52
  @thread ||= Thread.new do
49
53
  Thread.current.abort_on_exception = true
@@ -57,12 +61,12 @@ class AtDo
57
61
  break t-t_now if t > t_now
58
62
  begin
59
63
  a.call
60
- rescue => ex
64
+ rescue
61
65
  # exception handling is left to client code
62
66
  end
63
67
  @events.shift
64
68
  end
65
- @cvar.wait *duration
69
+ @cvar.wait(*duration)
66
70
  end
67
71
  end
68
72
  end
@@ -5,7 +5,7 @@ module AtDoTests
5
5
  def setup
6
6
  @s = make_atdo
7
7
  end
8
-
8
+
9
9
  def teardown
10
10
  @s.stop
11
11
  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.5'
4
+ version: '0.6'
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-09-06 00:00:00.000000000 Z
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: At time, do code.
14
14
  email: vjoel@users.sourceforge.net
@@ -18,8 +18,8 @@ extra_rdoc_files:
18
18
  - README.md
19
19
  - COPYING
20
20
  files:
21
- - README.md
22
21
  - COPYING
22
+ - README.md
23
23
  - Rakefile
24
24
  - lib/atdo.rb
25
25
  - test/test-atdo.rb
@@ -29,28 +29,28 @@ licenses:
29
29
  metadata: {}
30
30
  post_install_message:
31
31
  rdoc_options:
32
- - --quiet
33
- - --line-numbers
34
- - --inline-source
35
- - --title
32
+ - "--quiet"
33
+ - "--line-numbers"
34
+ - "--inline-source"
35
+ - "--title"
36
36
  - atdo
37
- - --main
37
+ - "--main"
38
38
  - README.md
39
39
  require_paths:
40
40
  - lib
41
41
  required_ruby_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - '>='
43
+ - - "~>"
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: '2.0'
46
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - '>='
48
+ - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 2.0.4
53
+ rubygems_version: 2.4.1
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: Schedule code to be executed at specified time.