track<T> method

Future<T> track<T>(
  1. Future<T> load, {
  2. required Future<void> release(),
})

Tracks load like add, and additionally takes ownership of it, so dispose gives the claim back.

Use this for the source-path loaders whose results live in a shared cache (loadScene, loadTexture). add only waits for a load; this also scopes it to the group's lifetime.

final level = ResourceGroup();
final terrain = level.track(loadScene('levels/ice.fsceneb'),
    release: () => releaseScene('levels/ice.fsceneb'));
// ...
level.dispose(); // gives the template's claim back

Implementation

Future<T> track<T>(
  Future<T> load, {
  required Future<void> Function() release,
}) {
  _releases.add(release);
  return add(load);
}