aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plum/rack/thread_pool.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plum/rack/thread_pool.rb')
-rw-r--r--lib/plum/rack/thread_pool.rb25
1 files changed, 2 insertions, 23 deletions
diff --git a/lib/plum/rack/thread_pool.rb b/lib/plum/rack/thread_pool.rb
index 7c3fc48..9e07943 100644
--- a/lib/plum/rack/thread_pool.rb
+++ b/lib/plum/rack/thread_pool.rb
@@ -5,9 +5,6 @@ module Plum
def initialize(size = 20)
@workers = Set.new
@jobs = Queue.new
- @tags = {}
- @cancels = Set.new
- @mutex = Mutex.new
size.times { |i|
spawn_worker
@@ -16,37 +13,19 @@ module Plum
# returns cancel token
def acquire(tag = nil, err = nil, &blk)
- @jobs << [blk, err, tag]
- tag
- end
-
- def cancel(tag)
- worker = @mutex.synchronize { @tags.delete?(tag) || (@cancels << tag; return) }
- @workers.delete(worker)
- worker.kill
- spawn_worker
+ @jobs << [blk, err]
end
private
def spawn_worker
t = Thread.new {
while true
- job, err, tag = @jobs.pop
- if tag
- next if @mutex.synchronize {
- c = @cancels.delete?(tag)
- @tags[tag] = self unless c
- c
- }
- end
-
+ job, err = @jobs.pop
begin
job.call
rescue => e
err << e if err
end
-
- @mutex.synchronize { @tags.delete(tag) } if tag
end
}
@workers << t