Method: Promise#sync

Defined in:
lib/volt/utils/promise_extensions.rb

#syncObject

Waits for the promise to be realized (resolved or rejected), then returns the resolved value or raises the rejection error. .sync only works on the server (not in opal), and will raise a warning if on the client.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/volt/utils/promise_extensions.rb', line 103

def sync
  raise ".sync can only be used on the server" if Volt.client?

  result = nil
  error = nil

  self.then do |val|
    result = val
  end.fail do |err|
    error = err
  end

  if error
    err_str = "Exception in Promise at .sync: #{error.inspect}"
    err_str += error.backtrace.join("\n") if error.respond_to?(:backtrace)
    Volt.logger.error(err_str)

    # The fail method in Promise is already defined, to re-raise the error,
    # we send fail
    Object.send(:fail, error)
  else
    return result
  end
end