class Airbrake::Promise

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/airbrake-ruby/promise.rbs

class Airbrake::Promise
  def initialize: () -> void
  def reject: (?String reason) -> untyped
  def rejected?: () -> untyped
  def resolve: (?Symbol reason) -> Airbrake::Promise
end

@since v1.7.0
@see github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent/promise.rb<br>@see developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise<br><br>promise is either resolved or rejected.
JavaScript), which allows chaining callbacks that are executed when the
Represents a simplified promise object (similar to promises found in

def initialize

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: () -> void

This signature was generated using 12 samples from 1 application.

def initialize
  @on_resolved = []
  @on_rejected = []
  @value = {}
  @mutex = Mutex.new
end

def reject(reason = 'rejected')

Experimental RBS support (using type sampling data from the type_fusion project).

def reject: (?String reason) -> untyped

This signature was generated using 3 samples from 1 application.

Returns:
  • (self) -

Parameters:
  • reason (String) --
def reject(reason = 'rejected')
  @mutex.synchronize do
    @value['error'] = reason
    @on_rejected.each { |callback| callback.call(reason) }
  end
  self
end

def rejected?

Experimental RBS support (using type sampling data from the type_fusion project).

def rejected?: () -> untyped

This signature was generated using 21 samples from 1 application.

Returns:
  • (Boolean) -
def rejected?
  @value.key?('error')
end

def rescue(&block)

Returns:
  • (self) -

Other tags:
    Yieldparam: error -

Other tags:
    Yield: - The error message from the API
def rescue(&block)
  @mutex.synchronize do
    if @value.key?('error')
      yield(@value['error'])
      return self
    end
    @on_rejected << block
  end
  self
end

def resolve(reason = 'resolved')

Experimental RBS support (using type sampling data from the type_fusion project).

def resolve: (?Symbol reason) -> Airbrake::Promise

This signature was generated using 6 samples from 1 application.

Returns:
  • (self) -

Parameters:
  • reason (Object) --
def resolve(reason = 'resolved')
  @mutex.synchronize do
    @value['ok'] = reason
    @on_resolved.each { |callback| callback.call(reason) }
  end
  self
end

def resolved?

Returns:
  • (Boolean) -
def resolved?
  @value.key?('ok')
end

def then(&block)

Returns:
  • (self) -

Other tags:
    Yieldparam: response - Contains the `id` & `url` keys

Other tags:
    Yield: -
def then(&block)
  @mutex.synchronize do
    if @value.key?('ok')
      yield(@value['ok'])
      return self
    end
    @on_resolved << block
  end
  self
end

def value

Other tags:
    Todo: - Get rid of this method and use an accessor. The resolved guard is

Other tags:
    Note: - This is a non-blocking call!

Returns:
  • (Hash) - either successful response containing the
def value
  return @value['ok'] if resolved?
  @value
end