class Fear::Promise

@api private

Attributes

options[R]
promise[R]

Public Class Methods

new(**options) click to toggle source

@param options [Hash] options passed to underlying Concurrent::Promise

Calls superclass method
# File lib/fear/promise.rb, line 13
def initialize(**options)
  super()
  @options = options
  @promise = Concurrent::Promise.new(options) do
    Fear.try { value }.flatten
  end
end

Public Instance Methods

complete(result) click to toggle source

Complete this promise with result @param result [Fear::Try] @return [Boolean] If the promise has already been completed returns

`false`, or `true` otherwise.

@raise [IllegalStateException] if promise already completed

# File lib/fear/promise.rb, line 85
def complete(result)
  if completed?
    false
  else
    set result
    promise.execute
    true
  end
end
complete!(result) click to toggle source

Complete this promise with result @param result [Fear::Try] @return [self] @raise [IllegalStateException] if promise already completed

# File lib/fear/promise.rb, line 71
def complete!(result)
  if complete(result)
    self
  else
    raise IllegalStateException, "Promise already completed."
  end
end
completed?() click to toggle source
# File lib/fear/promise.rb, line 24
def completed?
  complete?
end
failure(error) click to toggle source

Complete this promise with failure @param error [StandardError] @return [Boolean] @see complete

# File lib/fear/promise.rb, line 54
def failure(error)
  complete(Fear.failure(error))
end
failure!(error) click to toggle source

Complete this promise with failure @param error [StandardError] @return [self] @raise [IllegalStateException] @see complete!

# File lib/fear/promise.rb, line 63
def failure!(error)
  complete!(Fear.failure(error))
end
success(value) click to toggle source

Complete this promise with successful result @param value [any] @return [Boolean] @see complete

# File lib/fear/promise.rb, line 37
def success(value)
  complete(Fear.success(value))
end
success!(value) click to toggle source

Complete this promise with failure @param value [any] @return [self] @raise [IllegalStateException] @see complete!

# File lib/fear/promise.rb, line 46
def success!(value)
  complete!(Fear.success(value))
end
to_future() click to toggle source

@return [Fear::Future]

# File lib/fear/promise.rb, line 29
def to_future
  Future.new(promise, options)
end