Class: Steep::ThreadWaiter
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#waiter_threads ⇒ Object
readonly
Returns the value of attribute waiter_threads.
Instance Method Summary collapse
- #<<(thread) ⇒ Object
-
#initialize(objects = nil) ⇒ ThreadWaiter
constructor
A new instance of ThreadWaiter.
- #wait_one ⇒ Object
Constructor Details
#initialize(objects = nil) ⇒ ThreadWaiter
Returns a new instance of ThreadWaiter.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/steep/thread_waiter.rb', line 5 def initialize(objects = nil) @queue = Thread::Queue.new() @waiter_threads = Set[].compare_by_identity if objects objects.each do |object| thread = yield(object) self << thread end end end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
3 4 5 |
# File 'lib/steep/thread_waiter.rb', line 3 def queue @queue end |
#waiter_threads ⇒ Object (readonly)
Returns the value of attribute waiter_threads.
3 4 5 |
# File 'lib/steep/thread_waiter.rb', line 3 def waiter_threads @waiter_threads end |
Instance Method Details
#<<(thread) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/steep/thread_waiter.rb', line 17 def <<(thread) waiter_thread = Thread.new(thread) do |thread| # @type var thread: Thread Thread.current.report_on_exception = false begin thread.join ensure queue << thread end end waiter_threads << waiter_thread self end |
#wait_one ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/steep/thread_waiter.rb', line 35 def wait_one unless waiter_threads.empty? th = queue.pop() or raise waiter_threads.delete(th) th end end |