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



69
70
71
# File 'lib/msgr/test_pool.rb', line 69

def clear
  @instance ? @instance.clear : nil
end

.new(*args) ⇒ Object



61
62
63
# File 'lib/msgr/test_pool.rb', line 61

def new(*args)
  @instance ||= super(*args)
end

.run(*args) ⇒ Object



65
66
67
# File 'lib/msgr/test_pool.rb', line 65

def run(*args)
  new.run(*args)
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