Class: PulseMeter::CommandAggregator::Async
- Inherits:
-
Object
- Object
- PulseMeter::CommandAggregator::Async
show all
- Includes:
- Singleton
- Defined in:
- lib/pulse_meter/command_aggregator/async.rb
Constant Summary
collapse
- MAX_QUEUE_LENGTH =
10_000
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Async
13
14
15
16
17
18
19
20
|
# File 'lib/pulse_meter/command_aggregator/async.rb', line 13
def initialize
@max_queue_length = MAX_QUEUE_LENGTH
@queue = Queue.new
@buffer = []
@in_multi = false
@consumer_thread = run_consumer
at_exit{ wait_for_pending_events }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
30
31
32
33
|
# File 'lib/pulse_meter/command_aggregator/async.rb', line 30
def method_missing(*args)
@buffer << args
send_buffer_to_queue unless @in_multi
end
|
Instance Attribute Details
#max_queue_length ⇒ Object
Returns the value of attribute max_queue_length.
11
12
13
|
# File 'lib/pulse_meter/command_aggregator/async.rb', line 11
def max_queue_length
@max_queue_length
end
|
Instance Method Details
#multi ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/pulse_meter/command_aggregator/async.rb', line 22
def multi
@in_multi = true
yield
ensure
@in_multi = false
send_buffer_to_queue
end
|
#wait_for_pending_events(max_seconds = 1) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/pulse_meter/command_aggregator/async.rb', line 35
def wait_for_pending_events(max_seconds = 1)
left_to_wait = max_seconds.to_f
sleep_step = 0.01
while has_pending_events? && left_to_wait > 0
left_to_wait -= sleep_step
sleep(sleep_step)
end
end
|