Class: Msgr::TestPool

Inherits:
Object
  • Object
show all
Defined in:
lib/msgr/test_pool.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestPool

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

.clearObject 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

#clearObject



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(message, &block)
  @mutex.synchronize do
    @queue << [block, message]
    @event.signal
  end
end

#resetObject



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