loadMany method

Future<List<V>> loadMany(
  1. List<K> keys
)

Loads multiple keys, promising an array of values:

final loadedItems = await myLoader.loadMany([ 'a', 'b' ]);

This is similar to the more verbose:

final loadedItems = await Future.wait([
      myLoader.load('a'),
      myLoader.load('b')
    ]);

Implementation

Future<List<V>> loadMany(List<K> keys) {
  // Support ArrayLike by using only minimal property access
  final loadFutures = <Future<V>>[];
  for (var i = 0; i < keys.length; i++) {
    // TODO: 3E this.load(keys[i]).catch(error => error)
    /// However it is different in the case where any load fails. Where
    /// Future.all() would reject, loadMany() always resolves, however each
    /// result is either a value or an Error instance.
    ///
    ///     var [ a, b, c ] = await myLoader.loadMany([ 'a', 'b', 'badkey' ]);
    ///     // c instanceof Error
    ///
    loadFutures.add(this.load(keys[i]));
  }
  return Future.wait(loadFutures);
}