close method

void close()

Undeclares the publisher and releases native resources.

Safe to call multiple times -- subsequent calls are no-ops.

Also detaches this object's finalizer, so the safety net cannot release it a second time.

Implementation

void close() {
  if (_closed) return;
  _closed = true;
  // Unconditional: detaching a key that was never attached (the `ml:ON`
  // path) is a no-op, and a branch here would be one more place for the two
  // configurations to drift apart.
  publisherFinalizer.detach(this);
  bindings.zd_publisher_drop(_ptr.cast());
  _matchingPort?.close();
  unawaited(_matchingController?.close());
  calloc.free(_ptr);
}