class R3Status::Blocks::AsyncBlock
A base block for blocks who need to run the update procedure at a different interval than general update interval, or ones who need to run in the background.
Attributes
update_interval[RW]
The update interval (in seconds) of the block.
Public Class Methods
new(**args, &block)
click to toggle source
Creates a new instance of this class. If a block is passed, it will be stored and yielded when the block is clicked.
Calls superclass method
# File lib/r3status/blocks/async.rb, line 11 def initialize(**args, &block) args = {update_interval: 3}.merge(args) super(args, &block) end
Public Instance Methods
async_update()
click to toggle source
When implemented in derived classes, updates the text and color of this block. Implmentations should set the full_text and text_color attributes.
# File lib/r3status/blocks/async.rb, line 31 def async_update; end
terminate()
click to toggle source
Signals the block to release any resources.
# File lib/r3status/blocks/async.rb, line 25 def terminate @updater_thread.kill end
update()
click to toggle source
When first called, starts the update loop. Ignored afterwards.
# File lib/r3status/blocks/async.rb, line 17 def update return unless @updater_thread.nil? @updater_thread = Thread.new do loop_with_interval(update_interval) { async_update } end end