run static method

PreloadRequest run({
  1. required Iterable<Loader> loaders,
  2. Iterable<String> paths = const [],
  3. bool manifest = false,
  4. int concurrency = _CONCURRENCY,
  5. Duration timeout = _TIMEOUT,
})

Runs one load through a throwaway preload built from loaders.

Everything it creates is released once the load finishes, the returned request included, so this is for loads with nothing to keep around:

await Preload.run(loaders: [Loader.image()], manifest: true);

The request is still returned, so progress is available for as long as the load is running. Unlike load, do not dispose it yourself, and do not listen to it after it completes.

Implementation

static PreloadRequest run({
  required Iterable<Loader> loaders,
  Iterable<String> paths = const [],
  bool manifest = false,
  int concurrency = _CONCURRENCY,
  Duration timeout = _TIMEOUT,
}) {
  final preload = Preload(
    concurrency: concurrency,
    timeout: timeout,
  );

  for (final loader in loaders) {
    preload.register(loader);
  }

  final request = preload.load(
    manifest: manifest,
    paths: paths,
  );

  // Listeners get their last notification before this runs, since the request
  // reports itself done on the way out of the load.
  request
      .whenComplete(() async {
        request.dispose();
        await preload.dispose();
      })
      // The caller awaits the request itself; this branch must not surface a
      // second, unhandled copy of the same failure.
      .ignore();

  return request;
}