Methods

Instance Public methods

pending?()

Returns whether the associated query is still being executed or not.

📝 Source code
# File activerecord/lib/active_record/promise.rb, line 13
    def pending?
      @future_result.pending?
    end
🔎 See on GitHub

then(&block)

Returns a new ActiveRecord::Promise that will apply the passed block when the value is accessed:

Post.async_pluck(:title).then { |title| title.upcase }.value
# => "POST TITLE"
📝 Source code
# File activerecord/lib/active_record/promise.rb, line 36
    def then(&block)
      Promise.new(@future_result, @block ? @block >> block : block)
    end
🔎 See on GitHub

value()

Returns the query result. If the query wasn’t completed yet, accessing #value will block until the query completes. If the query failed, #value will raise the corresponding error.

📝 Source code
# File activerecord/lib/active_record/promise.rb, line 20
    def value
      return @value if defined? @value

      result = @future_result.result
      @value = if @block
        @block.call(result)
      else
        result
      end
    end
🔎 See on GitHub