Class: Msgr::TestPool
- Inherits:
-
Object
- Object
- Msgr::TestPool
- Defined in:
- lib/msgr/test_pool.rb
Class Method Summary collapse
- .clear ⇒ Object (also: reset)
- .new(*args) ⇒ Object
- .run(**kwargs) ⇒ Object
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ TestPool
constructor
A new instance of TestPool.
- #post(message, &block) ⇒ Object
- #reset ⇒ Object
- #run(**kwargs) ⇒ Object
Constructor Details
#initialize ⇒ TestPool
Returns a new instance of TestPool.
5 6 7 8 9 |
# File 'lib/msgr/test_pool.rb', line 5 def initialize(*) @queue = [] @mutex = Mutex.new @event = ConditionVariable.new end |
Class Method Details
.clear ⇒ Object Also known as: reset
67 68 69 |
# File 'lib/msgr/test_pool.rb', line 67 def clear @instance&.clear end |
.new(*args) ⇒ Object
59 60 61 |
# File 'lib/msgr/test_pool.rb', line 59 def new(*args) @instance ||= super # rubocop:disable Naming/MemoizedInstanceVariableName end |
.run(**kwargs) ⇒ Object
63 64 65 |
# File 'lib/msgr/test_pool.rb', line 63 def run(**kwargs) new.run(**kwargs) end |
Instance Method Details
#clear ⇒ Object
24 25 26 27 28 |
# File 'lib/msgr/test_pool.rb', line 24 def clear @mutex.synchronize do @queue.clear end end |
#post(message, &block) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/msgr/test_pool.rb', line 11 def post(, &block) @mutex.synchronize do @queue << [block, ] @event.signal end end |
#reset ⇒ Object
30 31 32 33 34 |
# File 'lib/msgr/test_pool.rb', line 30 def clear @mutex.synchronize do @queue.clear end end |
#run(**kwargs) ⇒ Object
18 19 20 21 22 |
# File 'lib/msgr/test_pool.rb', line 18 def run(**kwargs) @mutex.synchronize do ns_run(**kwargs) end end |