class ActiveRecord::Promise
def initialize(future_result, block) # :nodoc:
def initialize(future_result, block) # :nodoc: @future_result = future_result @block = block end
def inspect # :nodoc:
def inspect # :nodoc: "#<ActiveRecord::Promise status=#{status}>" end
def pending?
def pending? @future_result.pending? end
def pretty_print(q) # :nodoc:
def pretty_print(q) # :nodoc: q.text(inspect) end
def status
def status if @future_result.pending? :pending elsif @future_result.canceled? :canceled else :complete end end
def then(&block)
Post.async_pick(:title).then { |title| title.upcase }.value
when the value is accessed:
Returns a new +ActiveRecord::Promise+ that will apply the passed block
def then(&block) Promise.new(@future_result, @block ? @block >> block : block) end
def value
If the query wasn't completed yet, accessing +#value+ will block until the query completes.
Returns the query result.
def value return @value if defined? @value result = @future_result.result @value = if @block @block.call(result) else result end end