Class: Picdown::MultiThread
- Inherits:
-
Object
- Object
- Picdown::MultiThread
- Defined in:
- lib/picdown/multithread.rb
Instance Attribute Summary collapse
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Instance Method Summary collapse
- #add(*args, &block) ⇒ Object
-
#initialize(pool) ⇒ MultiThread
constructor
A new instance of MultiThread.
- #invoke ⇒ Object
Constructor Details
#initialize(pool) ⇒ MultiThread
Returns a new instance of MultiThread.
9 10 11 12 13 |
# File 'lib/picdown/multithread.rb', line 9 def initialize(pool) @pool = pool @threads = [] @queue = Queue.new end |
Instance Attribute Details
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
7 8 9 |
# File 'lib/picdown/multithread.rb', line 7 def pool @pool end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
7 8 9 |
# File 'lib/picdown/multithread.rb', line 7 def queue @queue end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
7 8 9 |
# File 'lib/picdown/multithread.rb', line 7 def threads @threads end |
Instance Method Details
#add(*args, &block) ⇒ Object
15 16 17 |
# File 'lib/picdown/multithread.rb', line 15 def add(*args, &block) queue << [block, args] end |
#invoke ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/picdown/multithread.rb', line 19 def invoke 1.upto(pool) { threads << spawn_thread } threads.each do |t| trap('INT') { Thread.kill(t) } t.join end end |