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



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

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

Instance Method Details

#abortObject

Abort the immediate.



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

def abort
  return if aborted?

  @aborted = true
  prevent

  self
end

#aborted?Boolean

Check if the immediate has been aborted.

Returns:

  • (Boolean)


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

def aborted?
  @aborted
end

#dispatchObject

Dispatch the immediate.



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

#preventObject



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

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