send method

Future<void> send()

Send the push message.

This also schedules the timeout to be triggered in the future.

Implementation

Future<void> send() async {
  if (_received is PushResponse && _received!.isTimeout) {
    _logger.warning('Trying to send push $ref after timeout');
    return;
  }
  _logger.finer('Sending out push for $ref');
  _sent = true;
  _awaitingReply = false;

  startTimeout();
  try {
    await _channel.socket.sendMessage(Message(
      event: event!,
      topic: _channel.topic,
      payload: payload!(),
      ref: ref,
      joinRef: _channel.joinRef,
    ));
    // ignore: avoid_catches_without_on_clauses
  } catch (err, stacktrace) {
    _logger.warning(
      'Caught error for push $ref',
      err,
      stacktrace,
    );
    _receiveResponse(err);
  }
}