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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b01b56f2d0d88ec08d5176a59a2de1dfe8b025e
4
- data.tar.gz: 78df656923eac0cad6786f66711c96bf7418b006
3
+ metadata.gz: a250c679853af97347a737874d8a0a8b3b7ddb78
4
+ data.tar.gz: fe3bcde1000a4cc3fbcb1f56f297fd79aa74b8cd
5
5
  SHA512:
6
- metadata.gz: 86dd766848014e7b269fe8cb8e913a3ce8dfd413c38495303938631dfe5f1aa99036e40540704199eea6eacfef25720cd2b1d3646fccd22de54c3ba84729f99e
7
- data.tar.gz: b2e0f32c4e36c6f762585873137415aa059c80bebee8467759f56c1cab83bd7be9ef16d0042e5a65ac0bd7df677349ee0f24d88ff5dff0a5d70aa26f6e316d9b
6
+ metadata.gz: 2208038144729ad0d336aa9ce65e5d3968b23ac3d154d9434fc6e7990886578c42b694606d659dc9aab22d2e55446546bb82c0103956001face9683074413d03
7
+ data.tar.gz: 3955b07024be6c971a0ed947ef9252dfefa167e43f6e8da2f7a9066193b521ed6278153a04f5706fa168ca6847c12439bf26fc354b21130c24251928ac3082d1
@@ -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!
@@ -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 do |task|
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 do |task|
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"
@@ -1,3 +1,4 @@
1
+ require "thread"
1
2
  require "forwardable"
2
3
 
3
4
  class Performer
@@ -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 = Mutex.new
7
- @queue_cond = Performer::ConditionVariable.new
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
- while empty? and open?
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
@@ -1,4 +1,4 @@
1
1
  class Performer
2
2
  # Current version of Performer.
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
@@ -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", [">= 3.0.0.rc1", "< 4.0"]
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
25
  spec.add_development_dependency "yard", "~> 0.8"
26
26
  end
@@ -56,7 +56,7 @@ describe Performer::Queue do
56
56
  Thread.new(queue) { |q| dequeue(q) }
57
57
  end
58
58
 
59
- before { wait_until_sleep(waiter) }
59
+ before { wait_until(waiter, "sleep") }
60
60
 
61
61
  specify "is awoken when an object is added" do
62
62
  queue.enq(1) { raise "enq failed" }
@@ -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
- wait_until_sleep(thread)
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
- wait_until_sleep(thread)
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) { wait_until_sleep(waiter) }
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
@@ -73,7 +73,7 @@ describe Performer do
73
73
  it "performs a clean shutdown, allowing scheduled tasks to finish" do
74
74
  stopgap = Queue.new
75
75
  waiter = Thread.new(Thread.current) do |thread|
76
- wait_until_sleep(thread)
76
+ wait_until(thread, "sleep")
77
77
  stopgap.push :go
78
78
  end
79
79
 
@@ -2,8 +2,8 @@ require "performer"
2
2
  require "timeout"
3
3
 
4
4
  module ConcurrencyUtilities
5
- def wait_until_sleep(thread)
6
- Thread.pass until thread.status == "sleep"
5
+ def wait_until(thread, status)
6
+ Thread.pass until thread.status == status
7
7
  end
8
8
  end
9
9
 
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.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-03 00:00:00.000000000 Z
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: '4.0'
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: '4.0'
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/puddle/queue_spec.rb
98
- - spec/puddle/task_spec.rb
99
- - spec/puddle_spec.rb
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.1
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/puddle/queue_spec.rb
127
- - spec/puddle/task_spec.rb
128
- - spec/puddle_spec.rb
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: