use<T> method

Future<T> use<T>(
  1. Pod pod,
  2. FutureOr<T> cb()
)

Listen to a pod, run the given cb (which can return a Future), then remove the listener once the cb is complete.

Implementation

Future<T> use<T>(Pod<dynamic> pod, FutureOr<T> Function() cb) async {
  final remove = mount(pod);

  try {
    return await cb();
  } finally {
    remove();
  }
}