listen method

AsyncReply listen(
  1. dynamic event
)

Implementation

AsyncReply<dynamic> listen(event) {
  if (_destroyed) throw new Exception("Trying to access destroyed object");
  if (_suspended) throw new Exception("Trying to access suspended object");

  EventTemplate? et = event is EventTemplate
      ? event
      : instance?.template.getEventTemplateByName(event);

  if (et == null)
    return AsyncReply<dynamic>().triggerError(new AsyncException(
        ErrorType.Management, ExceptionCode.MethodNotFound.index, ""));

  if (!et.listenable)
    return AsyncReply().triggerError(new AsyncException(
        ErrorType.Management, ExceptionCode.NotListenable.index, ""));

  return _connection?.sendListenRequest(_instanceId as int, et.index)
      as AsyncReply;
}