Class: Browser::Delay

Inherits:
Object show all
Defined in:
opal/browser/delay.rb

Overview

Allows you to delay the call to a function which gets called after the given time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, time, &block) ⇒ Delay

Create and start a timeout.

Parameters:

  • window (Window)

    the window to start the timeout on

  • time (Float)

    seconds after which the block is called



17
18
19
20
21
# File 'opal/browser/delay.rb', line 17

def initialize(window, time, &block)
  @window = Native.convert(window)
  @after  = time
  @block  = block
end

Instance Attribute Details

#afterFloat (readonly)

Returns the seconds after which the block is called.

Returns:

  • (Float)

    the seconds after which the block is called



11
12
13
# File 'opal/browser/delay.rb', line 11

def after
  @after
end

Instance Method Details

#abortObject

Abort the timeout.



24
25
26
# File 'opal/browser/delay.rb', line 24

def abort
  `#@window.clearTimeout(#@id)`
end

#startObject

Start the delay.



29
30
31
# File 'opal/browser/delay.rb', line 29

def start
  @id = `#@window.setTimeout(#{@block.to_n}, #@after * 1000)`
end