close method
Removes this publication from the embedded node.
Idempotent for a given handle. This closes only the exact mapping created for this handle. Replaced mappings and mappings from a newer runtime are left untouched.
Implementation
Future<void> close() {
final existing = _closeFuture;
if (existing != null) return existing;
late final Future<void> attempt;
attempt = Future<void>.sync(_closeFn).then<void>(
(_) {
if (identical(_closeFuture, attempt)) {
_publishedServiceFinalizer.detach(this);
}
},
onError: (Object error, StackTrace stackTrace) {
// Native retains exact ownership on a confirmed-not-applied failure.
// Keep the GC fallback attached and let a later explicit close retry.
// The identity check also closes the synchronous-throw assignment race.
if (identical(_closeFuture, attempt)) {
_closeFuture = null;
}
Error.throwWithStackTrace(error, stackTrace);
},
);
_closeFuture = attempt;
return attempt;
}