class Fear::Promise
@api private
Attributes
Public Class Methods
@param options [Hash] options passed to underlying Concurrent::Promise
# 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 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 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
# File lib/fear/promise.rb, line 24 def completed? complete? end
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
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
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
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
@return [Fear::Future]
# File lib/fear/promise.rb, line 29 def to_future Future.new(promise, options) end