Class: Flydata::QueueableThread
- Inherits:
-
Object
- Object
- Flydata::QueueableThread
- Defined in:
- lib/flydata/queueable_thread.rb
Constant Summary collapse
- MAX_JOBS =
60
Instance Method Summary collapse
-
#initialize(max_jobs = MAX_JOBS) ⇒ QueueableThread
constructor
A new instance of QueueableThread.
- #join ⇒ Object
- #run(&block) ⇒ Object
Constructor Details
#initialize(max_jobs = MAX_JOBS) ⇒ QueueableThread
Returns a new instance of QueueableThread.
5 6 7 8 9 10 |
# File 'lib/flydata/queueable_thread.rb', line 5 def initialize(max_jobs = MAX_JOBS) @queue = SizedQueue.new(max_jobs) @stop = false @thread = Thread.new(&method(:run_loop)) @thread.abort_on_exception = true end |
Instance Method Details
#join ⇒ Object
16 17 18 19 20 |
# File 'lib/flydata/queueable_thread.rb', line 16 def join @stop = true @queue << nil if @queue.empty? # wake up the thread @thread.join end |
#run(&block) ⇒ Object
12 13 14 |
# File 'lib/flydata/queueable_thread.rb', line 12 def run(&block) @queue << block end |