runWithOutputAsync<T> method

Future<T> runWithOutputAsync<T>(
  1. FutureOr<T> body(
    1. RenderOutput out
    ), {
  2. bool clearOnEnd = false,
})

Runs body with a RenderOutput, ensuring cleanup after awaited work.

Implementation

Future<T> runWithOutputAsync<T>(
  FutureOr<T> Function(RenderOutput out) body, {
  bool clearOnEnd = false,
}) {
  final out = RenderOutput();
  start();
  return Future.sync(() => body(out)).whenComplete(() {
    end();
    if (clearOnEnd) out.clear();
  });
}