execute method

Future execute([
  1. List args = const []
])

Always returns a Future, regardless of whether the function is sync or async

Implementation

Future<dynamic> execute([List<dynamic> args = const []]) async {
  final invocation = Invocation(command: this, args: args);

  FutureOr<dynamic> callNext(int index) {
    return _interceptors[index](invocation, () => callNext(index + 1));
  }

  // Ensure the return type is a Future
  return await Future.sync(() => callNext(0));
}