wait function

Future wait(
  1. List<String> topics, {
  2. bool sticky = true,
  3. Duration? timeout,
})

Implementation

Future<dynamic> wait(List<String> topics,
    {bool sticky = true, Duration? timeout}) async {
  var stream = subscribe(topics).stream;

  if (timeout != null) {
    stream = stream.timeout(timeout, onTimeout: (EventSink ev) {
      ev.close();
    });
  }

  await for (Message msg in stream) {
    if (!sticky && msg.sticky) continue;
    return msg.data;
  }
  throw (TimeoutException('Timeout on wait function'));
}