lib/dataloader.rb
# Loads a key, returning a [Promise](https://github.com/lgierth/promise.rb) for the value represented by that key.
#
# You can resolve this promise when you actually need the value with `promise.sync`.
#
# All calls to `#load` are batched until the first `#sync` is encountered. Then is starts batching again, et caetera.
#
# @param key [Object] key to load using `batch_load` proc
# @return [Promise<Object>] A Promise of computed value
# @example Load promises of two users and resolve them:
#   user_loader = Dataloader.new do |ids|
#     User.find(*ids)
#   end
#
#   user1_promise = user_loader.load(1)
#   user2_promise = user_loader.load(2)
#
#   user1 = user1_promise.sync
#   user2 = user2_promise.sync
Loads a key, returning a [Promise] for the value represented by that key.
You can resolve this promise when you actually need the value with `promise.sync`.

All calls to `#load` are batched until the first `#sync` is encountered. Then is starts batching again, et caetera.
Loads a key returning a [ Promise ] for the value represented by that key . You can resolve this promise when you actually need the value with ` promise . sync ` . All calls to ` #load ` are batched until the first ` #sync ` is encountered . Then is starts batching again et caetera .
def load(key)
    if key.nil?
      raise TypeError, "#load must be called with a key, but got: nil"
    end
    result = compute_if_absent(key) do
      batch_promise.queue(key)
    end
    unless result.is_a?(Promise)
      return Promise.new.fulfill(result)
    end
    result
  end
def load ( key ) if key . nil? raise TypeError , "#load must be called with a key, but got: nil" end result = compute_if_absent ( key ) do batch_promise . queue ( key ) end unless result . is_a? ( Promise ) return Promise . new . fulfill ( result ) end result end
Loads a key, returning a [Promise](https://github.com/lgierth/promise.rb) for the value represented by that key.
Loads a key returning a [ Promise ] ( https : // github . com / lgierth / promise . rb ) for the value represented by that key .
A Promise of computed value
A Promise of computed value
Promise<Object>
key
key to load using `batch_load` proc
key to load using ` batch_load ` proc
example
Load promises of two users and resolve them: user_loader = Dataloader.new do |ids| User.find(*ids) end user1_promise = user_loader.load(1) user2_promise = user_loader.load(2) user1 = user1_promise.sync user2 = user2_promise.sync
Load promises of two users and resolve them : user_loader = Dataloader . new do |ids| User . find ( * ids ) end user1_promise = user_loader . load ( 1 ) user2_promise = user_loader . load ( 2 ) user1 = user1_promise . sync user2 = user2_promise . sync