onAck<T extends DataObject> method

void onAck<T extends DataObject>(
  1. MessageHandler<AcknowledgedMessage<T>> handler
)

Registers a handler for when an AcknowledgedMessage of type T is received from a connection.

Implementation

void onAck<T extends DataObject>(
  MessageHandler<AcknowledgedMessage<T>> handler,
) {
  _ackSubscriptions.add(
    acknowledgedPackets.where((ack) => ack.object is T).map((ack) {
      final connection = _findExistingConnection(ack.address) ??
          Connection(clientSalt: 0, serverSalt: 0, address: ack.address);
      return AcknowledgedMessage<T>(connection, ack.cast<T>());
    }).listen(handler),
  );
}