Class: Browser::Immediate

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

Overview

Class to easily create and dispatch an immediate call.

Immediate calls are deferred function calls that happen as soon as they can be scheduled.

Compatibility

The compatibility layer will try various implementations in the following order.

The order has been chosen from best to worst for both performance and preemptiveness.

Instance Method Summary collapse

Constructor Details

#initialize(func, args, &block) ⇒ Immediate

Create an immediate for the given function which will be called with the arguments and block.

Parameters:

  • func (Proc)

    the function to call

  • args (Array)

    the arguments to call it with


28
29
30
31
32
33
# File 'opal/browser/immediate.rb', line 28

def initialize(func, args, &block)
  @aborted   = false
  @function  = func
  @arguments = args
  @block     = block
end

Instance Method Details

#abortObject

Abort the immediate.


117
118
119
120
121
122
123
124
# File 'opal/browser/immediate.rb', line 117

def abort
  return if aborted?

  @aborted = true
  prevent

  self
end

#aborted?Boolean

Check if the immediate has been aborted.

Returns:

  • (Boolean)

127
128
129
# File 'opal/browser/immediate.rb', line 127

def aborted?
  @aborted
end

#dispatchObject

Dispatch the immediate.


# File 'opal/browser/immediate.rb', line 35

#preventObject


47
48
49
# File 'opal/browser/immediate.rb', line 47

def prevent
  `window.clearImmediate(#@id)`
end