executeBundleAsAsync<T> method

Future<T> executeBundleAsAsync<T>(
  1. AstBundle bundle, {
  2. String? entryPoint,
  3. String name = 'main',
  4. List<Object?>? positionalArgs,
  5. Map<String, Object?>? namedArgs,
  6. D4rtExecutionHooks? hooks,
})

Async variant of executeBundleAs — awaits the result if it is a Future before unwrapping to T.

Use this when the bundle's entry point is async (or otherwise returns a Future). When the bundle is synchronous the awaited value is the raw return — both paths converge on D4.unwrapAs for the cast.

Implementation

Future<T> executeBundleAsAsync<T>(
  AstBundle bundle, {
  String? entryPoint,
  String name = 'main',
  List<Object?>? positionalArgs,
  Map<String, Object?>? namedArgs,
  D4rtExecutionHooks? hooks,
}) async {
  final raw = executeBundle(
    bundle,
    entryPoint: entryPoint,
    name: name,
    positionalArgs: positionalArgs,
    namedArgs: namedArgs,
    hooks: hooks,
  );
  // DASY1: the unwrap uses THIS run's visitor, captured before the await.
  // [visitor] belongs to whichever run started last, and another run on
  // this runner may start while this one's Future is pending.
  final runVisitor = _visitor;
  final resolved = raw is Future ? await raw : raw;
  return D4.unwrapAs<T>(resolved, visitor: runVisitor);
}