Class: TelestreamCloud::ParallelUploader::ThreadPool
- Inherits:
-
Object
- Object
- TelestreamCloud::ParallelUploader::ThreadPool
- Defined in:
- lib/telestream_cloud/parallel_uploader.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
- #<<(*args) ⇒ Object
-
#initialize(size, &block) ⇒ ThreadPool
constructor
A new instance of ThreadPool.
- #join ⇒ Object
Constructor Details
#initialize(size, &block) ⇒ ThreadPool
Returns a new instance of ThreadPool.
6 7 8 9 10 |
# File 'lib/telestream_cloud/parallel_uploader.rb', line 6 def initialize(size, &block) @size = size @queue = Queue.new @worker = block end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
4 5 6 |
# File 'lib/telestream_cloud/parallel_uploader.rb', line 4 def queue @queue end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/telestream_cloud/parallel_uploader.rb', line 4 def size @size end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
4 5 6 |
# File 'lib/telestream_cloud/parallel_uploader.rb', line 4 def worker @worker end |
Instance Method Details
#<<(*args) ⇒ Object
12 13 14 |
# File 'lib/telestream_cloud/parallel_uploader.rb', line 12 def <<(*args) queue.push(args) end |
#join ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/telestream_cloud/parallel_uploader.rb', line 16 def join size.times.map do Thread.new(queue) do begin while args = queue.pop(true) worker.call(*args) end rescue ThreadError end end end.map(&:join) end |