performer 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/performer.rb +14 -14
- data/lib/performer/condition_variable.rb +1 -0
- data/lib/performer/queue.rb +5 -5
- data/lib/performer/version.rb +1 -1
- data/performer.gemspec +1 -1
- data/spec/{puddle → performer}/queue_spec.rb +1 -1
- data/spec/{puddle → performer}/task_spec.rb +3 -3
- data/spec/{puddle_spec.rb → performer_spec.rb} +1 -1
- data/spec/spec_helper.rb +2 -2
- metadata +14 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a250c679853af97347a737874d8a0a8b3b7ddb78
|
4
|
+
data.tar.gz: fe3bcde1000a4cc3fbcb1f56f297fd79aa74b8cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2208038144729ad0d336aa9ce65e5d3968b23ac3d154d9434fc6e7990886578c42b694606d659dc9aab22d2e55446546bb82c0103956001face9683074413d03
|
7
|
+
data.tar.gz: 3955b07024be6c971a0ed947ef9252dfefa167e43f6e8da2f7a9066193b521ed6278153a04f5706fa168ca6847c12439bf26fc354b21130c24251928ac3082d1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
v1.0.1:
|
2
|
+
- Make Performer::Queue#enq re-entrant, allows scheduling tasks from
|
3
|
+
object finalizers (at least in MRI) [868f8ca0]
|
4
|
+
- Keep track of currently executing tasks internally. No public API,
|
5
|
+
but should help with debugging. [d35438f4]
|
6
|
+
|
7
|
+
v1.0.0:
|
8
|
+
- First release!
|
data/lib/performer.rb
CHANGED
@@ -22,6 +22,8 @@ class Performer
|
|
22
22
|
@queue = Performer::Queue.new
|
23
23
|
@running = true
|
24
24
|
@thread = Thread.new(&method(:run_loop))
|
25
|
+
|
26
|
+
@current_task = nil
|
25
27
|
@shutdown_task = Task.new(lambda do
|
26
28
|
@running = false
|
27
29
|
nil
|
@@ -80,13 +82,7 @@ class Performer
|
|
80
82
|
|
81
83
|
def run_loop
|
82
84
|
while @running
|
83
|
-
open = @queue.deq
|
84
|
-
begin
|
85
|
-
task.call
|
86
|
-
rescue Performer::Task::Error
|
87
|
-
# No op. Allows cancelling scheduled tasks.
|
88
|
-
end
|
89
|
-
end
|
85
|
+
open = @queue.deq { |task| with_task(task, &:call) }
|
90
86
|
|
91
87
|
if not open and @queue.empty?
|
92
88
|
@running = false
|
@@ -95,15 +91,19 @@ class Performer
|
|
95
91
|
ensure
|
96
92
|
@queue.close
|
97
93
|
until @queue.empty?
|
98
|
-
@queue.deq
|
99
|
-
begin
|
100
|
-
task.cancel
|
101
|
-
rescue Performer::Task::Error
|
102
|
-
# Shutting down. Don't care.
|
103
|
-
end
|
104
|
-
end
|
94
|
+
@queue.deq { |task| with_task(task, &:cancel) }
|
105
95
|
end
|
106
96
|
end
|
97
|
+
|
98
|
+
def with_task(task)
|
99
|
+
@current_task = task
|
100
|
+
yield task
|
101
|
+
rescue Performer::Task::Error
|
102
|
+
# Performer calling task does not care if you cancelled
|
103
|
+
# task, or if you called task earlier. We skip it.
|
104
|
+
ensure
|
105
|
+
@current_task = nil
|
106
|
+
end
|
107
107
|
end
|
108
108
|
|
109
109
|
require "performer/condition_variable"
|
data/lib/performer/queue.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
require "monitor"
|
2
|
+
|
1
3
|
class Performer
|
2
4
|
# Similar to the stdlib Queue, but with a thread-safe way of closing it down.
|
3
5
|
class Queue
|
4
6
|
def initialize
|
5
7
|
@queue = []
|
6
|
-
@queue_mutex =
|
7
|
-
@queue_cond =
|
8
|
+
@queue_mutex = Monitor.new
|
9
|
+
@queue_cond = @queue_mutex.new_cond
|
8
10
|
@undefined = {}
|
9
11
|
@open = true
|
10
12
|
end
|
@@ -57,9 +59,7 @@ class Performer
|
|
57
59
|
end
|
58
60
|
|
59
61
|
obj, was_open = @queue_mutex.synchronize do
|
60
|
-
|
61
|
-
@queue_cond.wait(@queue_mutex)
|
62
|
-
end
|
62
|
+
@queue_cond.wait_while { empty? and open? }
|
63
63
|
|
64
64
|
obj = if empty?
|
65
65
|
undefined
|
data/lib/performer/version.rb
CHANGED
data/performer.gemspec
CHANGED
@@ -21,6 +21,6 @@ and optionally waiting for the return value.}
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
23
23
|
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "rspec",
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
25
|
spec.add_development_dependency "yard", "~> 0.8"
|
26
26
|
end
|
@@ -12,7 +12,7 @@ describe Performer::Task do
|
|
12
12
|
it "raises an error when called during execution" do
|
13
13
|
task = Performer::Task.new(lambda { sleep })
|
14
14
|
thread = Thread.new(task, &:call)
|
15
|
-
|
15
|
+
wait_until(thread, "sleep")
|
16
16
|
|
17
17
|
lambda { task.call }.should raise_error(Performer::Task::InvariantError)
|
18
18
|
end
|
@@ -50,7 +50,7 @@ describe Performer::Task do
|
|
50
50
|
it "raises an error when called during execution" do
|
51
51
|
task = Performer::Task.new(lambda { sleep; :ok })
|
52
52
|
thread = Thread.new(task, &:call)
|
53
|
-
|
53
|
+
wait_until(thread, "sleep")
|
54
54
|
|
55
55
|
lambda { task.cancel }.should raise_error(Performer::Task::InvariantError)
|
56
56
|
|
@@ -90,7 +90,7 @@ describe Performer::Task do
|
|
90
90
|
|
91
91
|
context "task receives a result later on" do
|
92
92
|
let(:waiter) { Thread.new(task, &:value) }
|
93
|
-
before(:each) {
|
93
|
+
before(:each) { wait_until(waiter, "sleep") }
|
94
94
|
|
95
95
|
it "is woken up once a value is available" do
|
96
96
|
task.call
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: performer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kim Burgestrand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,22 +42,16 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.0.0.rc1
|
48
|
-
- - "<"
|
45
|
+
- - "~>"
|
49
46
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
47
|
+
version: '3.0'
|
51
48
|
type: :development
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
|
-
- - "
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: 3.0.0.rc1
|
58
|
-
- - "<"
|
52
|
+
- - "~>"
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
54
|
+
version: '3.0'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: yard
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +78,7 @@ files:
|
|
84
78
|
- ".gitignore"
|
85
79
|
- ".rspec"
|
86
80
|
- ".travis.yml"
|
81
|
+
- CHANGELOG.md
|
87
82
|
- Gemfile
|
88
83
|
- LICENSE.txt
|
89
84
|
- README.md
|
@@ -94,9 +89,9 @@ files:
|
|
94
89
|
- lib/performer/task.rb
|
95
90
|
- lib/performer/version.rb
|
96
91
|
- performer.gemspec
|
97
|
-
- spec/
|
98
|
-
- spec/
|
99
|
-
- spec/
|
92
|
+
- spec/performer/queue_spec.rb
|
93
|
+
- spec/performer/task_spec.rb
|
94
|
+
- spec/performer_spec.rb
|
100
95
|
- spec/spec_helper.rb
|
101
96
|
homepage: ''
|
102
97
|
licenses:
|
@@ -118,13 +113,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
113
|
version: '0'
|
119
114
|
requirements: []
|
120
115
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.2.
|
116
|
+
rubygems_version: 2.2.2
|
122
117
|
signing_key:
|
123
118
|
specification_version: 4
|
124
119
|
summary: Schedule blocks in a background thread.
|
125
120
|
test_files:
|
126
|
-
- spec/
|
127
|
-
- spec/
|
128
|
-
- spec/
|
121
|
+
- spec/performer/queue_spec.rb
|
122
|
+
- spec/performer/task_spec.rb
|
123
|
+
- spec/performer_spec.rb
|
129
124
|
- spec/spec_helper.rb
|
130
125
|
has_rdoc:
|