class Browser::Interval
Allows you to create an interval that executes the function every given seconds.
@see developer.mozilla.org/en-US/docs/Web/API/Window.setInterval
Attributes
every[R]
@!attribute [r] every @return [Float] the seconds every which the block is called
Public Class Methods
new(window, time, &block)
click to toggle source
Create and start an interval.
@param window [Window] the window to start the interval on @param time [Float] seconds every which to call the block
# File lib/reactive_record/interval.rb, line 16 def initialize(window, time, &block) @window = Native.convert(window) @every = time @block = block @aborted = false end
Public Instance Methods
abort()
click to toggle source
Abort the interval, it won't be possible to start it again.
# File lib/reactive_record/interval.rb, line 35 def abort `#@window.clearInterval(#@id)` @aborted = true @id = nil end
aborted?()
click to toggle source
Check if the interval has been aborted.
# File lib/reactive_record/interval.rb, line 30 def aborted? @aborted end
call()
click to toggle source
Call the [Interval] block.
# File lib/reactive_record/interval.rb, line 61 def call @block.call end
start()
click to toggle source
Start the interval if it has been stopped.
# File lib/reactive_record/interval.rb, line 53 def start raise "the interval has been aborted" if aborted? return unless stopped? @id = `#@window.setInterval(#@block, #@every * 1000)` end
stop()
click to toggle source
Stop the interval, it will be possible to start it again.
# File lib/reactive_record/interval.rb, line 43 def stop return if stopped? `#@window.clearInterval(#@id)` @stopped = true @id = nil end
stopped?()
click to toggle source
Check if the interval has been stopped.
# File lib/reactive_record/interval.rb, line 25 def stopped? @id.nil? end