close method
Close the embedding model and release resources.
Implementation
@override
Future<void> close() async {
if (_isClosed) return;
_isClosed = true;
try {
await _worker.close();
} finally {
onClose();
// Deliberately AFTER the teardown, not before it. A listener is app code
// (`addCloseListener` is public) and `CloseNotifier` calls each one bare,
// so firing them first would let one throw exit here before
// `_worker.close()` was ever sent — a leaked isolate that `_isClosed`
// then makes unrecoverable. It happened once, in this branch.
//
// The window that ordering left — the cache still matching this model on
// params while the teardown ran — is closed by [isClosed] instead, which
// is already true above and which `EmbedderCache` checks on every read.
// That covers every implementation in one place, not just this one.
fireCloseListeners();
}
}