Command class
Concrete implementation of ICommand interface. Command allows to call a method or function using Command pattern.
Example
var command = 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
Properties
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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
Parameters args) → List< ValidationResult> -
Validates the command
Parameters args
before execution using the defined schema.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited