hasMatchingSubscribers method

bool hasMatchingSubscribers()

Returns whether any subscribers currently match this advanced publisher's key expression.

Canon's own semantics: true from the moment the first matching subscriber connects until the last one disconnects.

Throws StateError if this publisher has been closed, and ZenohException carrying canon's code if the query itself fails.

Implementation

bool hasMatchingSubscribers() {
  _ensureOpen();
  final loaned = bindings.zd_advanced_publisher_loan(_ptr.cast());
  // ALLOCATE-LAST: the guard and the loan both precede the allocation, and
  // the finally below encloses every statement that can throw.
  final matching = calloc<Int>();
  try {
    final rc = bindings.zd_advanced_publisher_get_matching_status(
      loaned,
      matching,
    );
    if (rc != 0) {
      throw ZenohException('Failed to get matching status', rc);
    }
    return matching.value != 0;
  } finally {
    calloc.free(matching);
  }
}