Class: Phronomy::Concurrency::AsyncQueue
- Inherits:
-
Object
- Object
- Phronomy::Concurrency::AsyncQueue
- Defined in:
- lib/phronomy/engine/concurrency/async_queue.rb
Overview
Thread-safe FIFO queue used at explicit thread boundaries.
It intentionally contains no scheduler/Fiber semantics. Cooperative application execution is represented by FSMSession state and EventLoop events.
Instance Method Summary collapse
- #close ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(max_size: nil) ⇒ AsyncQueue
constructor
A new instance of AsyncQueue.
- #pop(timeout: nil) ⇒ Object
- #push(item) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(max_size: nil) ⇒ AsyncQueue
Returns a new instance of AsyncQueue.
10 11 12 |
# File 'lib/phronomy/engine/concurrency/async_queue.rb', line 10 def initialize(max_size: nil) @queue = max_size ? SizedQueue.new(max_size) : Thread::Queue.new end |
Instance Method Details
#close ⇒ Object
31 32 33 34 |
# File 'lib/phronomy/engine/concurrency/async_queue.rb', line 31 def close @queue.close self end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/phronomy/engine/concurrency/async_queue.rb', line 27 def empty? @queue.empty? end |
#pop(timeout: nil) ⇒ Object
19 20 21 |
# File 'lib/phronomy/engine/concurrency/async_queue.rb', line 19 def pop(timeout: nil) timeout ? @queue.pop(timeout: timeout) : @queue.pop end |
#push(item) ⇒ Object
14 15 16 17 |
# File 'lib/phronomy/engine/concurrency/async_queue.rb', line 14 def push(item) @queue.push(item) self end |
#size ⇒ Object
23 24 25 |
# File 'lib/phronomy/engine/concurrency/async_queue.rb', line 23 def size @queue.size end |