post method
Asynchronously sends this request to the server.
Fails if there are no event subscriptions to monitor the command execution. If this is
the desired behaviour, use CommandRequest.postAndForget(..).
When the command is sent, the event subscriptions created within this request are guaranteed to be active.
Returns a future which completes when the request is sent. If there was a network problem, the future, completes with an error.
If the server rejects the command with an error and the onError callback is set,
the callback will be triggered with the error. Otherwise, the error is silently ignored.
Implementation
Future<void> post({CommandErrorCallback? onError}) {
if (_futureSubscriptions.isEmpty) {
throw StateError('Use `observeEvents(..)` or `observeEventsWithContexts(..)` to observe'
' command results or call `postAndForget()` instead of `post()` if you observe'
' command results elsewhere.');
}
return Future.wait(_futureSubscriptions)
.then((_) => _client._postCommand(_command, onError));
}