Command class

Concrete implementation of [ICommand ICommand] interface. Command allows to call a method or function using Command pattern.

Example

var command = new Command("add", null, (correlationId, args) {
    var param1 = args.getAsFloat("param1");
    var param2 = args.getAsFloat("param2");
    var result = param1 + param2;
    return result;
});

result = await command.execute(
  "123",
  Parameters.fromTuples(
    ["param1", 2,
    "param2", 2]
  )).catch(err) {
    if (err!= null) print(err);
    else print("2 + 2 = " + result);
  }
);

// Console output: 2 + 2 = 4

See [ICommand] See [CommandSet]

Implemented types

Constructors

Command(String name, Schema schema, dynamic func)
Creates a new command object and assigns it's parameters. [...]

Properties

hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

execute(String correlationId, Parameters args) → Future
Executes the command. Before execution it validates [Parameters args] using the defined schema. The command execution intercepts exceptions raised by the called function and returns them as an error in callback. [...]
override
getName() → String
Gets the command name. Returns the name of this command.
override
validate(Parameters args) → List<ValidationResult>
Validates the command [Parameters args] before execution using the defined schema. [...]
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited