Class: ModSpox::Timer
- Inherits:
-
Object
- Object
- ModSpox::Timer
- Defined in:
- lib/mod_spox/Timer.rb
Instance Method Summary collapse
-
#add_message(message) ⇒ Object
- message
-
TimerAdd message Add a recurring code block.
-
#clear(message = nil) ⇒ Object
Clears all actions in the timer’s queue.
-
#initialize(timer, pipeline) ⇒ Timer
constructor
- timer
- ActionTimer to use pipeline
-
Message pipeline Creates a timer handler for interactions with the ActionTimer.
-
#remove_message(message) ⇒ Object
- message
-
TimerRemove message Remove an action from the timer.
-
#stop ⇒ Object
stop the timer.
Constructor Details
#initialize(timer, pipeline) ⇒ Timer
- timer
-
ActionTimer to use
- pipeline
-
Message pipeline
Creates a timer handler for interactions with the ActionTimer
12 13 14 15 16 17 18 19 20 |
# File 'lib/mod_spox/Timer.rb', line 12 def initialize(timer, pipeline) @pipeline = pipeline @timer = timer {:Internal_TimerAdd => :add_message, :Internal_TimerRemove => :remove_message, :Internal_TimerClear => :clear}.each_pair do |type,method| @pipeline.hook(self, method, type) end end |
Instance Method Details
#add_message(message) ⇒ Object
- message
-
TimerAdd message
Add a recurring code block
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mod_spox/Timer.rb', line 24 def () Logger.info("New block is being added to the timer") begin action = @timer.add(.period, .once, .data, .requester, &.block) @pipeline << Messages::Internal::TimerResponse.new(.requester, action, true, .id) rescue Object => boom Logger.error("Failed to add new block to timer: #{boom}") @pipeline << Messages::Internal::TimerResponse.new(.requester, nil, false, .id) end end |
#clear(message = nil) ⇒ Object
Clears all actions in the timer’s queue
44 45 46 47 48 49 50 |
# File 'lib/mod_spox/Timer.rb', line 44 def clear(=nil) if(.nil? || .plugin.nil?) @timer.clear else @timer.clear(.plugin) end end |
#remove_message(message) ⇒ Object
- message
-
TimerRemove message
Remove an action from the timer
37 38 39 40 41 |
# File 'lib/mod_spox/Timer.rb', line 37 def () @timer.remove(.action) Logger.info("Action has been removed from the Timer") @pipeline << Messages::Internal::TimerResponse.new(nil, .action, false, .id) end |
#stop ⇒ Object
stop the timer
53 54 55 |
# File 'lib/mod_spox/Timer.rb', line 53 def stop @timer.stop end |