class Volt::EventCounter
EventCounter
has an add
and remove
method, and when the first one is added will call the start proc (passed to new), and when the last is removed will call stop.
Attributes
count[R]
Public Class Methods
new(start, stop)
click to toggle source
# File lib/volt/utils/event_counter.rb, line 8 def initialize(start, stop) @start = start @stop = stop @count = 0 end
Public Instance Methods
add()
click to toggle source
# File lib/volt/utils/event_counter.rb, line 15 def add @count += 1 @start.call if @count == 1 end
remove()
click to toggle source
# File lib/volt/utils/event_counter.rb, line 21 def remove @count -= 1 fail 'count below 0' if @count < 0 @stop.call if @count == 0 end