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



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

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

Instance Method Details

#abortObject

Abort the immediate.



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

def abort
  return if aborted?

  @aborted = true
  prevent

  self
end

#aborted?Boolean

Check if the immediate has been aborted.

Returns:

  • (Boolean)


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

def aborted?
  @aborted
end

#dispatchObject

Dispatch the immediate.



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


#preventObject



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

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