timers 4.1.1 → 4.1.2
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.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +28 -0
- data/.ruby-version +1 -0
- data/.travis.yml +13 -10
- data/CHANGES.md +31 -23
- data/Gemfile +16 -3
- data/LICENSE +1 -1
- data/README.md +27 -17
- data/Rakefile +6 -3
- data/lib/timers.rb +4 -3
- data/lib/timers/events.rb +34 -39
- data/lib/timers/group.rb +30 -35
- data/lib/timers/timer.rb +25 -24
- data/lib/timers/version.rb +3 -1
- data/lib/timers/wait.rb +17 -18
- data/spec/spec_helper.rb +5 -3
- data/spec/{cancel_spec.rb → timers/cancel_spec.rb} +12 -13
- data/spec/{events_spec.rb → timers/events_spec.rb} +20 -21
- data/spec/{every_spec.rb → timers/every_spec.rb} +1 -2
- data/spec/{group_spec.rb → timers/group_spec.rb} +19 -18
- data/spec/{performance_spec.rb → timers/performance_spec.rb} +38 -42
- data/spec/timers/strict_spec.rb +36 -0
- data/spec/{timeout_spec.rb → timers/wait_spec.rb} +11 -10
- data/timers.gemspec +16 -13
- metadata +29 -41
- data/spec/strict_spec.rb +0 -37
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Event based timers:
|
4
4
|
|
@@ -39,7 +39,6 @@ require 'spec_helper'
|
|
39
39
|
# Serviced 1142649 events in 11.194903921 seconds, 102068.70405115146 e/s.
|
40
40
|
|
41
41
|
RSpec.describe Timers::Group do
|
42
|
-
|
43
42
|
it "runs efficiently" do
|
44
43
|
result = []
|
45
44
|
range = (1..500)
|
@@ -49,52 +48,49 @@ RSpec.describe Timers::Group do
|
|
49
48
|
range.each do |index|
|
50
49
|
offset = index.to_f / range.max
|
51
50
|
total += (duration / offset).floor
|
52
|
-
|
51
|
+
|
53
52
|
subject.every(index.to_f / range.max, :strict) { result << index }
|
54
53
|
end
|
55
|
-
|
54
|
+
|
56
55
|
subject.wait while result.size < total
|
57
|
-
|
56
|
+
|
58
57
|
rate = result.size.to_f / subject.current_offset
|
59
58
|
puts "Serviced #{result.size} events in #{subject.current_offset} seconds, #{rate} e/s."
|
60
|
-
|
61
|
-
expect(subject.current_offset).to be_within(TIMER_QUANTUM).of(duration)
|
62
|
-
end
|
63
|
-
|
64
|
-
=begin
|
65
|
-
it "runs efficiently at high volume" do
|
66
|
-
results = []
|
67
|
-
range = (1..300)
|
68
|
-
groups = (1..20)
|
69
|
-
duration = 101
|
70
59
|
|
71
|
-
|
72
|
-
@mutex = Mutex.new
|
73
|
-
start = Time.now
|
74
|
-
groups.each do |gi|
|
75
|
-
timers << Thread.new {
|
76
|
-
result = []
|
77
|
-
timer = Timers::Group.new
|
78
|
-
total = 0
|
79
|
-
range.each do |ri|
|
80
|
-
offset = ri.to_f / range.max
|
81
|
-
total += (duration / offset).floor
|
82
|
-
timer.every(ri.to_f / range.max, :strict) { result << ri }
|
83
|
-
end
|
84
|
-
timer.wait while result.size < total
|
85
|
-
@mutex.synchronize { results += result }
|
86
|
-
|
87
|
-
}
|
88
|
-
end
|
89
|
-
timers.each { |t| t.join }
|
90
|
-
finish = Time.now
|
91
|
-
|
92
|
-
rate = results.size.to_f / ( runtime = finish - start )
|
93
|
-
|
94
|
-
puts "Serviced #{results.size} events in #{runtime} seconds, #{rate} e/s; across #{groups.max} timers."
|
95
|
-
|
96
|
-
expect(runtime).to be_within(TIMER_QUANTUM).of(duration)
|
60
|
+
expect(subject.current_offset).to be_within(TIMER_QUANTUM).of(duration)
|
97
61
|
end
|
98
|
-
=end
|
99
62
|
|
63
|
+
# it "runs efficiently at high volume" do
|
64
|
+
# results = []
|
65
|
+
# range = (1..300)
|
66
|
+
# groups = (1..20)
|
67
|
+
# duration = 101
|
68
|
+
#
|
69
|
+
# timers = []
|
70
|
+
# @mutex = Mutex.new
|
71
|
+
# start = Time.now
|
72
|
+
# groups.each do |gi|
|
73
|
+
# timers << Thread.new {
|
74
|
+
# result = []
|
75
|
+
# timer = Timers::Group.new
|
76
|
+
# total = 0
|
77
|
+
# range.each do |ri|
|
78
|
+
# offset = ri.to_f / range.max
|
79
|
+
# total += (duration / offset).floor
|
80
|
+
# timer.every(ri.to_f / range.max, :strict) { result << ri }
|
81
|
+
# end
|
82
|
+
# timer.wait while result.size < total
|
83
|
+
# @mutex.synchronize { results += result }
|
84
|
+
#
|
85
|
+
# }
|
86
|
+
# end
|
87
|
+
# timers.each { |t| t.join }
|
88
|
+
# finish = Time.now
|
89
|
+
#
|
90
|
+
# rate = results.size.to_f / ( runtime = finish - start )
|
91
|
+
#
|
92
|
+
# puts "Serviced #{results.size} events in #{runtime} seconds, #{rate} e/s; across #{groups.max} timers."
|
93
|
+
#
|
94
|
+
# expect(runtime).to be_within(TIMER_QUANTUM).of(duration)
|
95
|
+
# end
|
100
96
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Timers::Group do
|
4
|
+
it "should not diverge too much" do
|
5
|
+
fired = :not_fired_yet
|
6
|
+
count = 0
|
7
|
+
quantum = 0.01
|
8
|
+
|
9
|
+
start_offset = subject.current_offset
|
10
|
+
Timers::Timer.new(subject, quantum, :strict, start_offset) do |offset|
|
11
|
+
fired = offset
|
12
|
+
count += 1
|
13
|
+
end
|
14
|
+
|
15
|
+
iterations = 1000
|
16
|
+
subject.wait while count < iterations
|
17
|
+
|
18
|
+
# In my testing on the JVM, without the :strict recurring, I noticed 60ms of error here.
|
19
|
+
expect(fired - start_offset).to be_within(quantum).of(iterations * quantum)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should only fire once" do
|
23
|
+
fired = :not_fired_yet
|
24
|
+
count = 0
|
25
|
+
|
26
|
+
start_offset = subject.current_offset
|
27
|
+
Timers::Timer.new(subject, 0, :strict, start_offset) do |offset|
|
28
|
+
fired = offset
|
29
|
+
count += 1
|
30
|
+
end
|
31
|
+
|
32
|
+
subject.wait
|
33
|
+
|
34
|
+
expect(count).to be == 1
|
35
|
+
end
|
36
|
+
end
|
@@ -1,29 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
require
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "timers/wait"
|
4
5
|
|
5
6
|
RSpec.describe Timers::Wait do
|
6
7
|
it "repeats until timeout expired" do
|
7
8
|
timeout = Timers::Wait.new(5)
|
8
9
|
count = 0
|
9
|
-
|
10
|
+
|
10
11
|
timeout.while_time_remaining do |remaining|
|
11
|
-
expect(remaining).to be_within(TIMER_QUANTUM).of
|
12
|
-
|
12
|
+
expect(remaining).to be_within(TIMER_QUANTUM).of(timeout.duration - count)
|
13
|
+
|
13
14
|
count += 1
|
14
15
|
sleep 1
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
expect(count).to eq(5)
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
it "yields results as soon as possible" do
|
21
22
|
timeout = Timers::Wait.new(5)
|
22
|
-
|
23
|
-
result = timeout.while_time_remaining do |
|
23
|
+
|
24
|
+
result = timeout.while_time_remaining do |_remaining|
|
24
25
|
break :done
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
expect(result).to eq(:done)
|
28
29
|
end
|
29
30
|
end
|
data/timers.gemspec
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require File.expand_path("../lib/timers/version", __FILE__)
|
3
5
|
|
4
6
|
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "timers"
|
8
|
+
gem.version = Timers::VERSION
|
5
9
|
gem.authors = ["Tony Arcieri"]
|
6
|
-
gem.email = ["
|
7
|
-
gem.
|
8
|
-
gem.summary = "Schedule procs to run after a certain time, or at periodic intervals, using any API that accepts a timeout"
|
10
|
+
gem.email = ["bascule@gmail.com"]
|
11
|
+
gem.licenses = ["MIT"]
|
9
12
|
gem.homepage = "https://github.com/celluloid/timers"
|
13
|
+
gem.summary = "Pure Ruby one-shot and periodic timers"
|
14
|
+
gem.description = <<-DESCRIPTION.strip.gsub(/\s+/, " ")
|
15
|
+
Schedule procs to run after a certain time, or at periodic intervals,
|
16
|
+
using any API that accepts a timeout.
|
17
|
+
DESCRIPTION
|
10
18
|
|
11
|
-
gem.files = `git ls-files`.split(
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
13
21
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name = "timers"
|
15
22
|
gem.require_paths = ["lib"]
|
16
|
-
gem.
|
17
|
-
gem.licenses = ['MIT']
|
18
|
-
|
19
|
-
gem.add_runtime_dependency 'hitimes'
|
23
|
+
gem.add_runtime_dependency "hitimes"
|
20
24
|
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency 'rspec', '~> 3.0.0'
|
25
|
+
gem.add_development_dependency "bundler"
|
23
26
|
end
|
metadata
CHANGED
@@ -1,60 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
14
|
+
name: hitimes
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - ">="
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: '0'
|
19
|
-
name: hitimes
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
|
-
name: rake
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
42
|
-
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 3.0.0
|
47
|
-
name: rspec
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 3.0.0
|
55
|
-
description: Pure Ruby one-shot and periodic timers
|
41
|
+
description: Schedule procs to run after a certain time, or at periodic intervals,
|
42
|
+
using any API that accepts a timeout.
|
56
43
|
email:
|
57
|
-
-
|
44
|
+
- bascule@gmail.com
|
58
45
|
executables: []
|
59
46
|
extensions: []
|
60
47
|
extra_rdoc_files: []
|
@@ -62,6 +49,8 @@ files:
|
|
62
49
|
- ".coveralls.yml"
|
63
50
|
- ".gitignore"
|
64
51
|
- ".rspec"
|
52
|
+
- ".rubocop.yml"
|
53
|
+
- ".ruby-version"
|
65
54
|
- ".travis.yml"
|
66
55
|
- AUTHORS.md
|
67
56
|
- CHANGES.md
|
@@ -75,14 +64,14 @@ files:
|
|
75
64
|
- lib/timers/timer.rb
|
76
65
|
- lib/timers/version.rb
|
77
66
|
- lib/timers/wait.rb
|
78
|
-
- spec/cancel_spec.rb
|
79
|
-
- spec/events_spec.rb
|
80
|
-
- spec/every_spec.rb
|
81
|
-
- spec/group_spec.rb
|
82
|
-
- spec/performance_spec.rb
|
83
67
|
- spec/spec_helper.rb
|
84
|
-
- spec/
|
85
|
-
- spec/
|
68
|
+
- spec/timers/cancel_spec.rb
|
69
|
+
- spec/timers/events_spec.rb
|
70
|
+
- spec/timers/every_spec.rb
|
71
|
+
- spec/timers/group_spec.rb
|
72
|
+
- spec/timers/performance_spec.rb
|
73
|
+
- spec/timers/strict_spec.rb
|
74
|
+
- spec/timers/wait_spec.rb
|
86
75
|
- timers.gemspec
|
87
76
|
homepage: https://github.com/celluloid/timers
|
88
77
|
licenses:
|
@@ -104,17 +93,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
93
|
version: '0'
|
105
94
|
requirements: []
|
106
95
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.5.2
|
108
97
|
signing_key:
|
109
98
|
specification_version: 4
|
110
|
-
summary:
|
111
|
-
any API that accepts a timeout
|
99
|
+
summary: Pure Ruby one-shot and periodic timers
|
112
100
|
test_files:
|
113
|
-
- spec/cancel_spec.rb
|
114
|
-
- spec/events_spec.rb
|
115
|
-
- spec/every_spec.rb
|
116
|
-
- spec/group_spec.rb
|
117
|
-
- spec/performance_spec.rb
|
118
101
|
- spec/spec_helper.rb
|
119
|
-
- spec/
|
120
|
-
- spec/
|
102
|
+
- spec/timers/cancel_spec.rb
|
103
|
+
- spec/timers/events_spec.rb
|
104
|
+
- spec/timers/every_spec.rb
|
105
|
+
- spec/timers/group_spec.rb
|
106
|
+
- spec/timers/performance_spec.rb
|
107
|
+
- spec/timers/strict_spec.rb
|
108
|
+
- spec/timers/wait_spec.rb
|
data/spec/strict_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Timers::Group do
|
5
|
-
it "should not diverge too much" do
|
6
|
-
fired = :not_fired_yet
|
7
|
-
count = 0
|
8
|
-
quantum = 0.01
|
9
|
-
|
10
|
-
start_offset = subject.current_offset
|
11
|
-
Timers::Timer.new(subject, quantum, :strict, start_offset) do |offset|
|
12
|
-
fired = offset
|
13
|
-
count += 1
|
14
|
-
end
|
15
|
-
|
16
|
-
iterations = 1000
|
17
|
-
subject.wait while count < iterations
|
18
|
-
|
19
|
-
# In my testing on the JVM, without the :strict recurring, I noticed 60ms of error here.
|
20
|
-
expect(fired - start_offset).to be_within(quantum).of(iterations * quantum)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should only fire once" do
|
24
|
-
fired = :not_fired_yet
|
25
|
-
count = 0
|
26
|
-
|
27
|
-
start_offset = subject.current_offset
|
28
|
-
Timers::Timer.new(subject, 0, :strict, start_offset) do |offset|
|
29
|
-
fired = offset
|
30
|
-
count += 1
|
31
|
-
end
|
32
|
-
|
33
|
-
subject.wait
|
34
|
-
|
35
|
-
expect(count).to be == 1
|
36
|
-
end
|
37
|
-
end
|