getMsg method

Future<T?> getMsg(
  1. Duration duration
)

Get the next message from the queue if any. returns data or null on error.

Implementation

Future<T?> getMsg(Duration duration) async {
  // don't use the timeout on the .next property as
  // it will eat the next incoming packet.
  // instead use hasNext and then use
  try {
    bool b = await _queue.hasNext.timeout(duration);
    if (b) {
      return await _queue.next;
    } else {
      // throw TimeoutException("Port was closed.");
      return null;
    }
  } on TimeoutException {
    return null;
  }
}