Module: Denko::Behaviors::Poller
- Included in:
- AnalogIO::Input, DigitalIO::Input, OneWire::Peripheral, Sensor::AHT10, Sensor::AHT20, Sensor::BME280, Sensor::BMP180, Sensor::DHT, Sensor::HTU31D, Sensor::Humidity, Sensor::QMP6988, Sensor::RCWL9620, Sensor::SHT3X, Sensor::Temperature
- Defined in:
- lib/denko/behaviors/poller.rb
Instance Attribute Summary
Attributes included from Threaded
Attributes included from Callbacks
Instance Method Summary collapse
- #poll(interval, *args, &block) ⇒ Object
- #poll_using(method, interval, *args, &block) ⇒ Object
- #stop ⇒ Object
Methods included from Threaded
#enable_interrupts, included, #stop_thread, #threaded, #threaded_loop
Methods included from Reader
#_read, #read, #read_using, #wait_for_read
Methods included from Callbacks
#add_callback, #callbacks, #initialize, #pre_callback_filter, #remove_callback, #update
Methods included from State
Instance Method Details
#poll(interval, *args, &block) ⇒ Object
21 22 23 |
# File 'lib/denko/behaviors/poller.rb', line 21 def poll(interval, *args, &block) poll_using(self.method(:_read), interval, *args, &block) end |
#poll_using(method, interval, *args, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/denko/behaviors/poller.rb', line 7 def poll_using(method, interval, *args, &block) unless [Integer, Float].include? interval.class raise ArgumentError, "wrong interval given to #poll : #{interval.inspect}" end stop add_callback(:poll, &block) if block_given? threaded_loop do method.call(*args) sleep interval end end |
#stop ⇒ Object
25 26 27 28 |
# File 'lib/denko/behaviors/poller.rb', line 25 def stop super if defined?(super) remove_callbacks :poll end |