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.



4
5
6
7
8
# File 'lib/msgr/test_pool.rb', line 4

def initialize(*)
  @queue = []
  @mutex = Mutex.new
  @event = ConditionVariable.new
end

Class Method Details

.clearObject Also known as: reset



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

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

.new(*args) ⇒ Object



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

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

.run(*args) ⇒ Object



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

def run(*args)
  new.run(*args)
end

Instance Method Details

#clearObject



23
24
25
26
27
# File 'lib/msgr/test_pool.rb', line 23

def clear
  @mutex.synchronize do
    @queue.clear
  end
end

#post(message, &block) ⇒ Object



10
11
12
13
14
15
# File 'lib/msgr/test_pool.rb', line 10

def post(message, &block)
  @mutex.synchronize do
    @queue << [block, message]
    @event.signal
  end
end

#resetObject



29
30
31
32
33
# File 'lib/msgr/test_pool.rb', line 29

def clear
  @mutex.synchronize do
    @queue.clear
  end
end

#run(**kwargs) ⇒ Object



17
18
19
20
21
# File 'lib/msgr/test_pool.rb', line 17

def run(**kwargs)
  @mutex.synchronize do
    ns_run(**kwargs)
  end
end