Class: Promise

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

Class Method Summary collapse

Class Method Details

.defer(*args, &block) ⇒ Object

Create a promise which will be resolved with the result of the immediate.

Parameters:

  • args (Array)

    the arguments the block will be called with



152
153
154
155
156
157
158
159
160
161
162
# File 'opal/browser/immediate.rb', line 152

def self.defer(*args, &block)
  new.tap {|promise|
    proc {
      begin
        promise.resolve(block.call(*args))
      rescue Exception => e
        promise.reject(e)
      end
    }.defer
  }
end