runCommand<TCommand extends ICommand<TResult>, TResult> method

Future<TResult> runCommand<TCommand extends ICommand<TResult>, TResult>(
  1. TCommand command
)

Executes the given command if a handler for it could be found, otherwise throws the StateError.

Implementation

Future<TResult> runCommand<TCommand extends ICommand<TResult>, TResult>(
  TCommand command,
) async {
  dynamic handler = _commandHandlers[TCommand];
  if (handler == null) {
    throw StateError(
      "No query handler has been registered for the $TCommand type.",
    );
  }

  ICommandHandler<TCommand, TResult> typedhandler = handler;
  return await typedhandler.handle(command);
}